Borrego
Borrego

Reputation: 41

Unable to resolve color value

I am trying to make my buttons change the color of their text when it is pressed but i ran into a problem that i cant solve. I get an error saying "unable to resolve color value" then it gives me the path to the file. here are my files im using

This one is in a new folder named color under resources and its called button

<?xml version="1.0" encoding="utf-8"?>
<selector xmlns:android="http://schemas.android.com/apk/res/android">
<item android:state_pressed="true" android:color="#ffff0000" />
<item android:state_focused="true" android:color="#ff0000ff" />
<item android:color="#ff000000" />
</selector>

And

<Button android:text="Main Menu" android:textColor="@color/button"
    android:layout_width="200px" android:id="@+id/mainmenu"
    android:layout_height="55px" android:layout_x="5dip"  
    android:layout_y="174dip"
    android:textSize="18px">
 </Button>

its driving me crazy if anybody could help me.

Upvotes: 4

Views: 4492

Answers (2)

Whiler
Whiler

Reputation: 8086

I successfully did it like this:

Files:

/drawable/button_states.xml
/layout/main.xml
/values/colors.xml

button_states.xml:

<?xml version="1.0" encoding="utf-8"?>
<selector xmlns:android="http://schemas.android.com/apk/res/android">
    <item android:state_pressed="true"
        android:color="@color/red" /> <!-- pressed -->
    <item android:state_focused="true"
        android:color="@color/blue_background" /> <!-- focused -->
    <item android:color="@color/white" /> <!-- default -->
</selector>

colors.xml:

<?xml version="1.0" encoding="utf-8"?>
<resources>
    <color name="blue_background">#FF2f74c3</color>
    <color name="white">#fefefe</color>
    <color name="red">#ff0000</color>
</resources>

layout.xml

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:orientation="vertical"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent"
    >
<Button
    android:layout_height="wrap_content"
    android:text="Button"
    android:id="@+id/button1"
    android:layout_width="wrap_content"
    android:textColor="@drawable/button_states" />
</LinearLayout>

Upvotes: 5

Macarse
Macarse

Reputation: 93143

Try android:background instead.

Upvotes: 0

Related Questions