How to disable/hide three-dot indicator(Option men

2019-01-16 14:01发布

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

I am running application as <uses-sdk android:minSdkVersion="5"/> in Manifest, code is compiled with 4.0. Three-dot indicator shows on every screen.

Example for preference activities i don't want show Three-dot indicator, since it does't have any menu options.

Adding android:targetSdkVersion="14" in manifest it works. However don't want hide/remove three dots button on all screens . Only in preference activities don't want to show this three dots button.

19条回答
狗以群分
2楼-- · 2019-01-16 14:33

override method and return false remember of not call super

 @Override
public boolean onCreateOptionsMenu(Menu menu) {
    return false;
}
查看更多
beautiful°
3楼-- · 2019-01-16 14:35

Way too late to the party here, I was trying to remove all my menu items and the 3-dots(option menu indicator), I did differently than the solution given here I am surprised that nobody had told it. There is a visibility tag that can be set to false and no changing of code in activity is required visibility=false does the trick

in res / menu /..

<item
    android:id="@+id/action_settings"
    android:orderInCategory="100"
    android:showAsAction="never"
    visibility=false
    android:title="@string/action_settings"/>
查看更多
够拽才男人
4楼-- · 2019-01-16 14:36

Do it like this.

@Override
public boolean onPrepareOptionsMenu(Menu menu) {
    // if nav drawer is opened, hide the action items
    boolean drawerOpen = mDrawerLayout.isDrawerOpen(leftDrawer);
    return (!drawerOpen);
}

I am checking if my navigation drawer is visible I will hide the menu and vice versa. You can use it according to you requirement. Hope this helps. Happy Coding. :)

查看更多
Rolldiameter
5楼-- · 2019-01-16 14:37

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);
}
查看更多
孤傲高冷的网名
6楼-- · 2019-01-16 14:37

Copy paste this code in main.xml in menu folder you just need to make the item android:visible="false"

    <?xml version="1.0" encoding="utf-8"?>
<menu xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:app="http://schemas.android.com/apk/res-auto">
    <item
        android:id="@+id/action_settings"
        android:orderInCategory="100"
        android:visible="false"
        android:title="@string/action_settings"
        app:showAsAction="never" />
</menu>
查看更多
我欲成王,谁敢阻挡
7楼-- · 2019-01-16 14:39

Following code worked for my app. Tried on Samsung Galaxy S4 (Android 4.3) and Nexus 4 (Android 4.2):

@Override
public boolean onPrepareOptionsMenu(Menu menu) {
    MenuItem item= menu.findItem(R.id.action_settings);
    item.setVisible(false);
    return true;
}
查看更多
登录 后发表回答