How to disable/hide three-dot indicator(Option menu indicator) on ICS handsets

后端 未结 19 1756
闹比i
闹比i 2020-12-04 19:29

How to disable/hide three-dot indicator(Option menu indicator) on ICS handsets which does\'t have menu button. ?

I am running application as

相关标签:
19条回答
  • 2020-12-04 19:47

    Just want to improve @war_hero answer. If You wanna set the visibility on run time You can use oncreateoptions menu parameter like this

    Menu overflow;
    
     @Override
    public boolean onCreateOptionsMenu(Menu menu) {
    
        getMenuInflater().inflate(R.menu.mymenu, menu);
        this.overflow = menu;
        return super.onCreateOptionsMenu(menu);
    }
    

    and then make a function to show or hide any menu item according to the index. for e.g.

    public void hideorShowMenuItems(boolean bool){
       overflow.getItem(1).setVisible(bool);
       overflow.getItem(2).setVisible(bool);
       overflow.getItem(3).setVisible(bool);
       overflow.getItem(4).setVisible(bool);
       overflow.getItem(5).setVisible(bool);
    }
    
    0 讨论(0)
  • 2020-12-04 19:49

    Override onPrepareOptionsMenu() in the fragment of the preference with this:

    @Override
    public boolean onPrepareOptionsMenu(Menu menu) {
        MenuItem item= menu.findItem(R.id.menu_settings);
        item.setVisible(false);
        super.onPrepareOptionsMenu(menu);
        return true;
    }
    

    if you have more then one item set all the items visibility flag to false

    and add the command setHasOptionsMenu(true); to the onCreate command

    after you will set all the visibility of the items to false the menu will disappear

    on activity, the only difference is the onPrepareOptionsMenu is boolean and you don't need to add the setHasOptionsMenu(true); command on the creation

    0 讨论(0)
  • 2020-12-04 19:50

    I just deleted the method :

    @Override
    public boolean onCreateOptionsMenu(com.actionbarsherlock.view.Menu menu) {
        getSupportMenuInflater().inflate(R.menu.main, menu);
        return true;
    }
    

    then that three-dot-menu goes away (:


    Hope it helps.

    0 讨论(0)
  • 2020-12-04 19:50

    I just used

     @Override
    public boolean onCreateOptionsMenu(Menu menu) {
        getMenuInflater().inflate(R.menu.main, menu);
        return true;
    }
    

    Where R.menu.main is only an empty menu xml

    <menu xmlns:android="http://schemas.android.com/apk/res/android" ></menu>
    
    0 讨论(0)
  • 2020-12-04 19:51

    override method and return false remember of not call super

     @Override
    public boolean onCreateOptionsMenu(Menu menu) {
        return false;
    }
    
    0 讨论(0)
  • 2020-12-04 19:52
     @Override
     public boolean onCreateOptionsMenu(Menu menu) {
           return false;
     }
    
    0 讨论(0)
提交回复
热议问题