I knew how to do it long ago, but I think it's best to come down.
Under the Drawable folder, create a new file with the following contents:
<?xml version= "1.0" encoding= "Utf-8"? ><selector xmlns:android= "http://schemas.android.com/apk/res/ Android "> <item android:drawable=" @drawable/co_2 "android:state_pressed=" true "/> <item android:drawable= "@drawable/co_2" android:state_focused= "true"/> <item android:drawable= "@drawable/co_ 1 "/></selector>
Then, in layout layouts, give the button: SetBackground.
Explain: Each item represents a constraint, so there are three constraints on the above file, state_pressed, state_focused, respectively, whether to press the state, to get the focus state, set the two states, click the button, the button will change the background, When not clicked, the background is: Co_1, that is, the last item without the state, indicating the background when the button is not clicked.
When you click the button, it shows different effects, backgrounds