Could not resolve color value

I am trying to get my buttons to change the color of their text when clicked, but I ran into a problem that I cannot solve. I get the error "Unable to resolve color value", after which it gives me the path to the file. here are my im files using

This file is located in a new folder called color under the resources and 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> 

it drives me crazy if anyone can help me.

+4
source share
2 answers

I have successfully done 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> 
+4
source

Try android:background .

0
source

Source: https://habr.com/ru/post/1338770/


All Articles