How do I get the android icons to change state (highlights)?
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?
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>
精彩评论