Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Is it possible to grey out (not just disable) a MenuItem in Android?

There's a question for the same functionality on Blackberry, and a few different threads referred to this bug (which has since been closed without resolution as far as I can tell), but I haven't found one specifically for Android.

I'm calling setEnabled(false) on certain MenuItems based on some state, but they visually look the same. I'd like them to be offset in some way, so that the user knows that the option currently isn't available -- is there any way to do that?

like image 749
Waynn Lue Avatar asked Mar 10 '12 01:03

Waynn Lue


People also ask

How do I turn off menu items?

To disable a menu item, set its Enabled property to False. In the following example, an event handler is attached to the OnClick event for the Edit item on a child form's menu bar. It sets Enabled for the Cut, Copy, and Delete menu items on the Edit menu based on whether RichEdit1 has selected text.

Which of the following method is used to enabling and disabling menu items?

To enable and disable menu items, use the MenuItem class's setEnabled method.

What is contextual menu in Android?

A context menu is a floating menu that appears when the user performs a long-click on an element. It provides actions that affect the selected content or context frame.


1 Answers

On all android versions, easiest way to use this to SHOW a menu action icon as disabled AND make it FUNCTION as disabled as well:

@Override public boolean onPrepareOptionsMenu(Menu menu) {      MenuItem item = menu.findItem(R.id.menu_my_item);      if (myItemShouldBeEnabled) {         item.setEnabled(true);         item.getIcon().setAlpha(255);     } else {         // disabled         item.setEnabled(false);         item.getIcon().setAlpha(130);     } } 
like image 81
Frank Avatar answered Sep 24 '22 21:09

Frank