在Button上觸摸按下的時(shí)候,Button有focused,pressed和default狀態(tài),可以使用不同的圖片來顯示這三種狀態(tài)。
先定義一個(gè)名為btnselector.xml文件,代碼如下:
- <?xml version="1.0" encoding="UTF-8"?>
- <selector xmlns:android="http://schemas.android.com/apk/res/android">
- <item
- android:state_focused="true"
- android:state_pressed="false"
- android:drawable="@drawable/focused"
- ></item>
- <item
- android:state_focused="true"
- android:state_pressed="true"
- android:drawable="@drawable/focusedpressed"
- ></item>
- <item
- android:state_focused="false"
- android:state_pressed="true"
- android:drawable="@drawable/pressed"
- ></item>
- <item
- android:drawable="@drawable/default"
- ></item>
-
- </selector>
ImageButton使用btnselector.xml如下:
- <ImageButton
- android:id="@+id/stop"
- android:layout_width="wrap_content"
- android:layout_height="wrap_content"
- android:src="@drawable/btnselector"
- android:background="#00000000"
- ></ImageButton>
android:src賦值為"@drawable/btnselector",而不是指向具體的圖片資源。
本站僅提供存儲(chǔ)服務(wù),所有內(nèi)容均由用戶發(fā)布,如發(fā)現(xiàn)有害或侵權(quán)內(nèi)容,請
點(diǎn)擊舉報(bào)。