Issue
I am worried that this is a duplicate question, but I have read these three questions and I'm still at a loss:
Setting background color from colours.xml throws invalid operation
How to define variable resource such as colours
Colour resource ID returning wrong value
I'm creating a Selector for a list view and setting the background of the item view as this selector. I want the selector to reference colours that I have defined in resource file, but I cannot get the colours to be recognised.
The colours resource file:
// colors.xml .. path=Resources\color\colours.xml
<?xml version="1.0" encoding="UTF-8" ?>
<resources>
<color name="background_default">#FFFFFFFF</color>
<color name="background_highlighted">#FFE9E9E9</color>
<color name="list_separator">#FFE6E6E6</color>
<color name="highlight">#FF00AEEE</color>
<color name="font_dark">#FF333333</color>
<color name="font_light">#FF808080</color>
</resources>
The selector:
// selector.xml .. path=Resources\drawable\selector.xml
<?xml version="1.0" encoding="UTF-8" ?>
<selector xmlns:android="http://schemas.android.com/apk/res/android">
<item
android:state_pressed="false"
android:state_selected="false"
android:drawable="@color/background_default" />
<item
android:state_pressed="false"
android:state_selected="true"
android:drawable="@color/background_highlighted" />
<item
android:state_pressed="true"
android:drawable="@color/highlight" />
</selector>
In the item view I use this:
android:background="@drawable/selector"
I get 3 errors that say No resource found that matches the given name (at 'color' with value '@color/background_default'). For each of the colours referenced in selector.xml, I've set colour.xml as an android resource and I've cleaned/resetthe solution a couple of times now. There has to be something I'm missing or doing wrong. Thanks for the help.
Solution
Try moving your colors to path Resources\values\Colors.xml
Answered By - snowCrabs
0 comments:
Post a Comment
Note: Only a member of this blog may post a comment.