In the development process, often encounter such a scene, click the button, the background color changes: In drawable, define Xxx.xml (selector)
<selectorxmlns:android= "Http://schemas.android.com/apk/res/android"> <Itemandroid:drawable= "#ee0000"android:state_focused= "true"/> <Itemandroid:drawable= "#ee0000"android:state_selected= "true"/> <Itemandroid:drawable= "#ee0000"android:state_pressed= "true"/> <Itemandroid:drawable= "#00ee00"/></selector>
Then set the android:background= "@drawable/xxx" in the button and it's OK.
In the case of TextView, you may also need to add the attribute android:clickable= "true";
Later, you will also encounter the font color of the button above changes when clicked:
Method is the same: Define the resource file
<selectorxmlns:android= "Http://schemas.android.com/apk/res/android"> <ItemAndroid:color= "@color/press"android:state_focused= "true"/> <ItemAndroid:color= "@color/press"android:state_selected= "true"/> <ItemAndroid:color= "@color/press"android:state_pressed= "true"/> <ItemAndroid:color= "@color/normal"/></selector>
Press Norma, which are color values of different states, are defined in color.
After that, android:textcolor= "@drawable/xxx" in TextView
PS: More suitable for beginners, their own study in the summary, the actual problems encountered.
Learn ing
Android Font Color change (click)