标签:
在drawable-hdpi中添加xml文件
<?xml version="1.0" encoding="utf-8"?> <selector xmlns:android="http://schemas.android.com/apk/res/android"> <item android:state_pressed="true" > <shape> <gradient android:startColor="#ff8c00" android:endColor="#FFFFFF" android:angle="270" /> <stroke android:width="2dp" android:color="#dcdcdc" /> <corners android:radius="10dp" /> <padding android:left="5dp" android:top="5dp" android:right="5dp" android:bottom="5dp" /> </shape> </item> <item android:state_focused="true" > <shape> <gradient android:startColor="#ffc2b7" android:endColor="#ffc2b7" android:angle="270" /> <stroke android:width="2dp" android:color="#dcdcdc" /> <corners android:radius="10dp" /> <padding android:left="5dp" android:top="5dp" android:right="5dp" android:bottom="5dp" /> </shape> </item> <item> <shape> <gradient android:startColor="#ff9d77" android:endColor="#ff9d77" android:angle="270" /> <stroke android:width="2dp" android:color="#fad3cf" /> <corners android:radius="10dp" /> <padding android:left="5dp" android:top="5dp" android:right="5dp" android:bottom="5dp" /> </shape> </item> </selector>
<?xml version="1.0" encoding="utf-8"?> <selector xmlns:android="http://schemas.android.com/apk/res/android"> <item android:drawable="@drawable/red" android:state_pressed="true"/> <!-- 被按压的时候 显示什么图形 注:图片大会异常 --> <item android:drawable="@drawable/red" android:state_focused="true"/> <!-- 获取焦点 --> <item android:drawable="@drawable/backward"/> <!-- 默认的时候 显示的图形 --> </selector>
图片太大程序会异常退出
设置android:background属性即可
<ImageView
android:id="@+id/image_back"
android:clickable="true"
android:layout_width="30dip"
android:layout_height="30.0dip"
android:scaleType="fitXY"
android:background="@drawable/style_back_selector" />
标签:
原文地址:http://www.cnblogs.com/huangzhen22/p/4803509.html