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

后端 未结 8 1113
旧时难觅i
旧时难觅i 2020-12-23 13:35

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 ca

相关标签:
8条回答
  • 2020-12-23 14:20

    setEnabled(false) works fine on API Level < 14 but on 14 the item still clickable.

    0 讨论(0)
  • 2020-12-23 14:26

    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);
        }
    }
    
    0 讨论(0)
提交回复
热议问题