您好,登錄后才能下訂單哦!
要自定義Button的背景圖像和狀態(tài)變化,可以使用selector來定義不同狀態(tài)下的背景圖像。以下是一個(gè)示例代碼:
<selector xmlns:android="http://schemas.android.com/apk/res/android">
<item android:drawable="@drawable/button_pressed" android:state_pressed="true"/>
<item android:drawable="@drawable/button_disabled" android:state_enabled="false"/>
<item android:drawable="@drawable/button_normal"/>
</selector>
在drawable文件夾下創(chuàng)建對(duì)應(yīng)的三個(gè)背景圖像文件,比如button_normal.png、button_pressed.png和button_disabled.png。
在布局文件中使用Button,并設(shè)置背景為自定義selector文件:
<Button
android:id="@+id/custom_button"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Custom Button"
android:background="@drawable/custom_button"/>
這樣就可以實(shí)現(xiàn)自定義Button的背景圖像和狀態(tài)變化了。當(dāng)Button被按下時(shí),背景會(huì)變成button_pressed.png;當(dāng)Button被禁用時(shí),背景會(huì)變成button_disabled.png;其他情況下背景為button_normal.png。
免責(zé)聲明:本站發(fā)布的內(nèi)容(圖片、視頻和文字)以原創(chuàng)、轉(zhuǎn)載和分享為主,文章觀點(diǎn)不代表本網(wǎng)站立場(chǎng),如果涉及侵權(quán)請(qǐng)聯(lián)系站長(zhǎng)郵箱:is@yisu.com進(jìn)行舉報(bào),并提供相關(guān)證據(jù),一經(jīng)查實(shí),將立刻刪除涉嫌侵權(quán)內(nèi)容。