How do I get the android icons to change state (highlights)?

╄→гoц情女王★ 提交于 2019-12-10 12:12:01

问题


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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!