Switch the picture when the button is pressed

Create a new button_checked.XML file under the res/drawble file

<?xml version="1.0" encoding="utf-8"?>
<selector xmlns:android="http://schemas.android.com/apk/res/android" >
   <item android:drawable="@drawable/quick_menu_select"  android:state_checked="true"></item>
   <item android:drawable="@drawable/tab_more" android:state_pressed="true"/>
    <item android:drawable="@drawable/quick_menu_unselect" ></item>
</selector>

then use this file in button

<RadioButton
    android:layout_height="wrap_content"  
    android:layout_width="wrap_content"  
    android:background="@drawable/button_checked" />

android:state_checked The image displayed after being selected

android:state_pressed Image displayed when pressed


Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=326276912&siteId=291194637