ActionBar MenuItem selector [closed]

半城伤御伤魂 提交于 2019-12-06 02:31:06

Is it possible to change the Image of a MenuItem when pressed and can that be done by a selector

Yep, absolutely. Here's an example:

Add a selector to your drawable folder.

<selector xmlns:android="http://schemas.android.com/apk/res/android">

    <!-- Pressed state -->
    <item android:drawable="@drawable/ic_action_your_pressed_icon" android:state_pressed="true"/>
    <!-- Default state -->
    <item android:drawable="@drawable/ic_action_your_default_icon"/>

</selector>

Apply the selector to your MenuItem using the icon attribute:

<menu xmlns:android="http://schemas.android.com/apk/res/android" >

    <item android:icon="@drawable/your_menu_item_selector" ... />

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