Can you make an action "unapproachable"?

I am using ActionBarSherlock library for my application for API level 10. I was wondering if it is possible to have an Action icon that does not respond when it was clicked.

<?xml version="1.0" encoding="utf-8"?>
<menu xmlns:android="http://schemas.android.com/apk/res/android">
    <item android:id="@+id/mainTopBluetoothState"
        android:icon="@drawable/bt_not_connected"
        android:orderInCategory="0"
        android:clickable="false"
        android:showAsAction="ifRoom" />

    <item android:id="@+id/mainTopAppState"
        android:title="App State"
        android:orderInCategory="1"
        android:showAsAction="ifRoom" />

</menu>

      

android:clickable="false"

does not raise an error, but the Action continues to respond when pressed while the application is running.

+3


source to share


3 answers


Try android:enabled

or setEnabled()

run onMenuItem

.



+11


source


mymenu.getItem(0//item number).setEnabled(false);

      

and when you setClickable

just want to write this ...



mymenu.getItem(0).setEnabled(true);

      

+3


source


You can do this in onPrepareOptionsMenu(Menu menu)

@Override
public boolean onPrepareOptionsMenu (Menu menu){
    super.onPrepareOptionsMenu(menu);

        MenuItem myItem = menu.findItem(R.id.myId);
        myItem.setEnabled(false);

    return true;  
}

      

The documentation recommends doing this as follows.

Prepare a display default menu to be displayed. This is called right before the menu is displayed, every time it is displayed. You can use this method to effectively enable / disable elements or otherwise dynamically change the content.

+1


source







All Articles