This is usually achieved by using a <selector> . For instance:
<?xml version="1.0" encoding="utf-8"?> <selector xmlns:android="http://schemas.android.com/apk/res/android"> <item android:state_pressed="true" android:drawable="@drawable/pressed" /> <item android:drawable="@drawable/normal" /> </selector>
The selector performs arbitration between other drawings depending on the state of the view in which it is located. You put the above xml into a file in res / drawable / and then used it as a background for your view. You must also have normal and pressed outputs.
You can also create selector selections in code where it is called StateListDrawable .
But maybe your solution is simpler ...
source share