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>