PHPFixing
  • Privacy Policy
  • TOS
  • Ask Question
  • Contact Us
  • Home
  • PHP
  • Programming
  • SQL Injection
  • Web3.0

Monday, November 7, 2022

[FIXED] How to disable a particular option from optionmenu across all the tabs in android?

 November 07, 2022     android, menu, tabs     No comments   

Issue

I am developing an application which consists of four tabs. Its also having six optionmenu which is common to all the four tabs and I need to disable one of the option menu depending on the current state of the application. Is there any way to disable particular option from the optionmenu across all the tabs??


Solution

To disable a menu item, you can override onPrepareOptionsMenu in your activity:

public boolean onPrepareOptionsMenu(Menu menu) {

    // To disable the item
    menu.findItem(R.id.the_menu_id).setEnabled(false);

    // To make the item invisible
    menu.findItem(R.id.the_menu_id).setVisibility(false);
}

If your tabs are composed of multiple views, then you only need to override the method in one place. If your tabs are composed of multiple activities, then you'll need to override the method in each of your activities and choose which items to display based on your application's state.



Answered By - Erich Douglass
Answer Checked By - Marie Seifert (PHPFixing Admin)
  • Share This:  
  •  Facebook
  •  Twitter
  •  Stumble
  •  Digg
Newer Post Older Post Home

0 Comments:

Post a Comment

Note: Only a member of this blog may post a comment.

Total Pageviews

Featured Post

Why Learn PHP Programming

Why Learn PHP Programming A widely-used open source scripting language PHP is one of the most popular programming languages in the world. It...

Subscribe To

Posts
Atom
Posts
Comments
Atom
Comments

Copyright © PHPFixing