java.lang.UnsupportedOperationException: Can't convert to color: type=0x1



I've been following throught the myfirstapp guide on Android developers training but I've come across a problem where they do not properly explain how to define colors.


They mention that to create a custom theme, you can declare your text colors as such:


themes.xml



<?xml version="1.0" encoding="utf-8"?>
<resources>
<!-- the theme applied to the application or activity -->
<style name="CustomActionBarTheme"
parent="@android:style/Theme.Holo.Light.DarkActionBar">
<item name="android:actionBarStyle">@style/MyActionBar</item>
<item name="android:textColor">@style/MyActionBarTitleText</item>
<item name="android:actionBarTabTextStyle">@style/MyActionBarTabText</item>
</style>

<!-- ActionBar styles -->
<style name="MyActionBar"
parent="@android:style/Widget.Holo.Light.ActionBar.Solid.Inverse">
<item name="android:background">@drawable/actionbar_background</item>
</style>

<!-- ActionBar title text -->
<style name="MyActionBarTitleText"
parent="@android:style/TextAppearance.Holo.Widget.ActionBar.Title">
<item name="android:textColor">@color/actionbar_text</item>
</style>

<!-- ActionBar tabs text styles -->
<style name="MyActionBarTabText"
parent="@android:style/Widget.Holo.ActionBar.TabText">
<item name="android:textColor">@color/actionbar_text</item>
</style>
</resources>


They do not mention how to specify @color/actionbar_text, but common sense (and some googling) indicates that a colors.xml file is required in the values package:


colors.xml



<?xml version="1.0" encoding="utf-8"?>
<resources>
<color name="actionbar_text">#ff355689</color>
</resources>


However, when trying to run the app, it gives an error:



Process: com.example.myfirstapp, PID: 25997
java.lang.RuntimeException: Unable to start activity ComponentInfo{com.example.myfirstapp/com.example.myfirstapp.MainActivity}: java.lang.UnsupportedOperationException: Can't convert to color: type=0x1


If I remove the line from colors.xml, it errors when it can't find the color reference. Im relatively certain my code is correct, can anyone see any errors?


android studio showing error


No comments:

Post a Comment