我有一个按钮,我将其背景设置为特定的选择器
。
目前选择器会更改按钮背景并更改图像作为背景。
我还想要更改背景颜色(图像周围是透明空间)。
这是选择器:
<?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
只是一种颜色。