我有一個按鈕,我將其背景設置爲具體的selector
。
選擇器當前更改按鈕背景並將圖像更改爲背景。
我也想要改變背景顏色(圖像是周圍有透明空間的圖標)。
這是選擇:Android:使用選擇器更改按鈕背景圖像和顏色
<?xml version="1.0" encoding="utf-8"?>
<selector
xmlns:android="http://schemas.android.com/apk/res/android" >
<!-- default -->
<item
android:state_pressed="false"
android:state_focused="false"
android:drawable="@drawable/menu_button_collapsed" >
</item>
<!-- button focused -->
<item
android:state_pressed="false"
android:state_focused="true"
android:drawable="@drawable/menu_button_collapsed_highlight"
android:drawable="@drawable/button_background" >
</item>
<!-- button pressed -->
<item
android:state_pressed="true"
android:state_focused="false"
android:drawable="@drawable/menu_button_collapsed_highlight"
android:drawable="@drawable/button_background" >
</item>
</selector>
正如你所看到的,我設置了drawable
屬性的兩倍,這是違法的,但是這是我真正想要的。
通知@drawable/button_background
只是顏色
謝謝你,偉大工程。 – SagiLow 2014-11-21 17:50:35