How to change the color of text and background when a button is clicked using xml?
To change the color of the text, I can do:
<selector xmlns:android="http://schemas.android.com/apk/res/android"> <item android:state_pressed="true" android:color="mycolor"/> <item android:color="mycolor2/> </selector>
To change the background I can do (using it in a selector / drawable element):
<shape xmlns:android="http://schemas.android.com/apk/res/android"> <solid android:color="#FF0079FF" /> </shape>
But how can I do both? Say I want:
- Default: black text / white background
- Click: white text / blue background
EDIT: answer
I completely forgot that the background and text color are controlled separately, so here is how I did it:
<Button android:textColor="@color/filtersbuttoncolors" android:background="@drawable/mybackgroundcolors" />
In mybackgroundcolors.xml I control the background and in filtersbuttoncolors.xml I control the color of the text. In both xml files, I control the status (clicked, selected, by default)
android colors button background status
Titmael Oct. 16 '13 at 10:13 2013-10-16 10:13
source share