標籤:
在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>
Button樣式檔案
<?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>
ImageView樣式檔案
圖片太大程式會異常退出
設定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" />
android樣式之按鈕&&圖片