tasomaniac
tasomaniac

Reputation: 10342

Unclickable menu item which is not greyed out in Android

I have a menu item in my overflow menu with no icon at all and I am using it as an information to the user which should not have been seen right away.

When I make it disabled, it will be greyed out. I want to make an item that is not clickable? How can I do that? Thank you.

Upvotes: 3

Views: 1316

Answers (1)

Piotr Chojnacki
Piotr Chojnacki

Reputation: 6857

In order to achieve this, you should specify your own style for ListView item 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>

It is a code taken from default button's xml. I changed it so that in state android:state_enabled="false" it still uses normal background.

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

Put it into xml file called for example my_item.xml, put it into drawable directory and then in xml where you create your item, set it's background to background="@drawable/my_item".

Upvotes: 2

Related Questions