按钮被按时候切换图片

在res/drawble文件下新建一个button_checked.XML文件

<?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>

然后在button中使用这个文件

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

android:state_checked  被选中后所显示的图片

android:state_pressed 被按住时候所显示的图片


猜你喜欢

转载自blog.csdn.net/qq_14907703/article/details/50755377