Unclickable menu item that is not greyed out in Android

I have a menu item in my overflow menu with no icon at all, and I'm using it as information for a user who shouldn't have been noticed right away.

When I disable it, it will be grayed out. I want to make an element that is not clickable? How can i do this? Thank.

+3


source to share


1 answer


To achieve this, you must specify your style for the element ListView

with selector

:

<selector xmlns:android="http://schemas.android.com/apk/res/android">
    <item android:state_window_focused="false" android:state_enabled="true"
        android:drawable="@drawable/btn_default_normal" />
    <item android:state_window_focused="false" android:state_enabled="false"
        android:drawable="@drawable/btn_default_normal" />
    <item android:state_pressed="true" 
        android:drawable="@drawable/btn_default_pressed" />
    <item android:state_focused="true" android:state_enabled="true"
        android:drawable="@drawable/btn_default_selected" />
    <item android:state_enabled="true"
        android:drawable="@drawable/btn_default_normal" />
    <item android:state_focused="true"
        android:drawable="@drawable/btn_default_normal_disable_focused" />
    <item
         android:drawable="@drawable/btn_default_normal" />
</selector>

      

This is the code taken from the standard xml button. I changed it so that in state android:state_enabled="false"

it still uses the normal background.



You can change it to whatever you want your object to look like.

Place it in an xml file called for example my_item.xml

put it in a drawing directory and then in the xml where you create your element set its background background="@drawable/my_item"

.

+2


source







All Articles