问题
I am using the Android SDK icon-button for refresh (ic_menu_refresh) in a widget and I need to change the selection state when it is pressed. How is this done? Do I define an XML for the button?
回答1:
You define the different states in xml via selector.
Sample (esp. see the state-attributes):
<?xml version="1.0" encoding="utf-8"?>
<selector xmlns:android="http://schemas.android.com/apk/res/android">
<item android:drawable="@drawable/bg_catlocfilter" android:state_pressed="false" />
<item android:drawable="@drawable/bg_catlocfilter_dark" android:state_pressed="true" />
<item android:drawable="@drawable/bg_catlocfilter" android:state_focused="false" />
<item android:drawable="@drawable/bg_catlocfilter_dark" android:state_focused="true" />
</selector>
来源:https://stackoverflow.com/questions/3380479/how-do-i-get-the-android-icons-to-change-state-highlights