50

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.

Saeed
  • 3,294
  • 5
  • 35
  • 52
Subba
  • 637
  • 1
  • 7
  • 13
  • you should definitely read http://android-developers.blogspot.com/2012/01/say-goodbye-to-menu-button.html if you haven't already... – Mike Ellery Feb 09 '12 at 22:40
  • 2
    Yes. I read about it. I still want to use overflow button on ICS handsets rather implementing action bar for short term to support users.It seem like there is no way to remove overflow button on certain screen not using this attribute "android:targetSdkVersion="14"" manifest. On preference activities overflow button shows even though there are no options. – Subba Feb 09 '12 at 23:08
  • @user1198982 did you ever find a solution for this issue, I also want to remove it when there are no options? – MikeIsrael May 16 '12 at 18:51
  • The right answer is given here: http://stackoverflow.com/questions/17914017/android-4-3-menu-item-showasaction-always-ignored – user3817420 Feb 23 '15 at 22:56

19 Answers19

34

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

Chad Nouis
  • 6,861
  • 1
  • 27
  • 28
Asaf Manassen
  • 3,893
  • 2
  • 21
  • 19
27

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.

alicanbatur
  • 2,172
  • 1
  • 28
  • 36
  • 1
    If you are using the Action Bar for other icons though, this will not work, as it disables all icons in the Action Bar. – Azurespot Jul 11 '14 at 03:49
  • if you want to use other buttons on this bar, don't delete the entire method, just comment this below statement //getSupportMenuInflater().inflate(R.menu.main, menu); – sifr_dot_in Apr 24 '19 at 03:53
17
 @Override
 public boolean onCreateOptionsMenu(Menu menu) {
       return false;
 }
Community
  • 1
  • 1
dnocode
  • 1,928
  • 1
  • 18
  • 21
9

There is no way to show/hide "three-dot" menu indicator for a single activity. You can hide this menu indicator only for entire app by specifying android:targetSdkVersion="14" (or above) in your manifest file.

However, this menu indicator is not showing on preferences activity if it extends from native android.preference.PreferenceActivity class. I have this scenario implemented in a few of my apps, and it works perfectly.

I assume you are using some custom preferences implementations which does not extends from PreferenceActivity. Android Dev Team suggests to always use PreferenceActivity for any preferences in your applications.

HitOdessit
  • 7,198
  • 4
  • 36
  • 59
6

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"/>
madhan kumar
  • 1,560
  • 2
  • 26
  • 36
Aniruddha K.M
  • 7,361
  • 3
  • 43
  • 52
5

override method and return false remember of not call super

 @Override
public boolean onCreateOptionsMenu(Menu menu) {
    return false;
}
dnocode
  • 1,928
  • 1
  • 18
  • 21
5

Remove this item in res / menu / main.xml

<item
    android:id="@+id/action_settings"
    android:orderInCategory="100"
    android:showAsAction="never"
    android:title="@string/action_settings"/>

In addition: do not add an item that has showAsAction="never"- this will avoid the dots from showing. If you have more items than can not be shown at once the dots will be there again (and they are items that are flagged ifRoom).

Francois
  • 10,730
  • 7
  • 47
  • 80
Weverton Souza
  • 391
  • 3
  • 14
  • Can you be a bit more verbose about what you're trying to say here? It's not clear how this answers the question. – Codeman Feb 05 '15 at 23:34
  • This is a good solution. Surprised that it is not upvoted more. The setvisible(false) solution did not work for me. Also you can add other action items as required. – everydayapps May 05 '15 at 14:28
4

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;
}
  • But this will show menu icon once and when you tap on it twice it will go away right? or it just doesn't show up when activity loads? – NinjaCoder Dec 20 '13 at 13:42
3
for hiding 3 dots in actionbar/ toolbar

 public boolean onCreateOptionsMenu(Menu menu) {
        // Inflate the menu; this adds items to the action bar if it is present.
        getMenuInflater().inflate(R.menu.activity_dash_board_drawer, menu);
        return false;  //for visible 3 dots change to true, hiding false
    }
Kishore Reddy
  • 2,394
  • 1
  • 19
  • 15
2

You can actually change the Android targetVersion thus forcing the 3-dot menu to either hide or show. You need to override onCreate of your Activity like this :

@Override
public void onCreate(Bundle savedInstanceState) {
    getApplicationInfo().targetSdkVersion = 10; // To enable the 3-dot menu call this code before super.OnCreate
    super.onCreate(savedInstanceState); 
}

@Override
public void onCreate(Bundle savedInstanceState) {
    getApplicationInfo().targetSdkVersion = 14; // To disable the 3-dot menu call this code before super.OnCreate
    super.onCreate(savedInstanceState); 
}

Tested on Android 4.x.x and Android 3.0

user3866289
  • 131
  • 1
  • 2
  • This was the perfect solution for me (to get rid of the 3 dots). I used it on an older app, targeting 2.3, and it worked in the emulator with no problems. Worked on my 4.4 real device, and 2.3.3 real device as well. Thanks! – Richard Sep 24 '15 at 00:00
2

I just excluded the "onCreateOptionsMenu"-method:

@Override
public boolean onCreateOptionsMenu(Menu menu) 
{
    //Inflate the menu; this adds items to the action bar if it is present.
    getMenuInflater().inflate(R.menu.menu_planos, menu);
    return true;
}
Cyphrags
  • 528
  • 1
  • 7
  • 16
GCoe
  • 849
  • 4
  • 14
  • 30
2

If you simply want to hide the button, this solution is a bit of a hack but works across all versions of Android (using AppCompat) and doesn't affect your other menu items:

styles.xml

<style name="AppTheme" parent="Theme.AppCompat.Light">
    ...
    <item name="android:actionOverflowButtonStyle">@style/AppTheme.Overflow</item>
    <!-- If you're using AppCompat, instead use -->
    <item name="actionOverflowButtonStyle">@style/AppTheme.Overflow</item>
</style>

<style name="AppTheme" />
<style name="AppTheme.Overflow">
    <item name="android:src">@null</item>
</style>

If you want the Overflow button hidden only on some screens, you could make this an alternate theme (change AppTheme above to AppTheme.NoOverflow) that only certain activities use :

AndroidManifest.xml

<activity android:name=".NoOverflowActivity"
          android:theme="@style/AppTheme.NoOverflow" >

This effectively just makes the icon have no width and height. I rarely recommend opposing design guidelines but in my scenario we used dedicated hardware that did not properly report a menu button was present.

Stephen Kidson
  • 2,819
  • 3
  • 20
  • 20
  • +1! This was the only solution that allowed me to hide the overflow button but still manually open the Options menu :) Thanks! – Machine Tribe Jan 04 '19 at 18:05
2

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);
}
codepeaker
  • 420
  • 8
  • 15
2

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>
Karan Shaw
  • 1,206
  • 10
  • 11
1

Should be:

<item
    android:id="@+id/linearlayout_splash"
    android:orderInCategory="100"
    android:showAsAction="never"
    android:visible="false"
    android:title="@string/action_settings"/>
Vachy
  • 11
  • 2
1

If MainActivity is

public class MainActivity extends AppCompatActivity

In MainActivity Class, Remove the below code.

@Override
public boolean onCreateOptionsMenu(Menu menu) {
    // Inflate the menu; this adds items to the action bar if it is present.
    getMenuInflater().inflate(R.menu.main, menu);
    return true;
}

@Override
public boolean onOptionsItemSelected(MenuItem item) {
    // Handle action bar item clicks here. The action bar will
    // automatically handle clicks on the Home/Up button, so long
    // as you specify a parent activity in AndroidManifest.xml.
    int id = item.getItemId();

    //noinspection SimplifiableIfStatement
    if (id == R.id.action_settings) {
        return true;
    }

    return super.onOptionsItemSelected(item);
}
Rijul Sudhir
  • 2,064
  • 1
  • 15
  • 19
0

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. :)

Atul O Holic
  • 6,692
  • 4
  • 39
  • 74
0

This is how I find a solution of mine. It maybe helpful.

@Override
public boolean onKeyDown(int keycode, KeyEvent event ) {
    //KEYCODE_MENU
 if(keycode == KeyEvent.KEYCODE_MENU){
 /* AlertDialog.Builder dialogBuilder 
  = new AlertDialog.Builder(this)
  .setMessage("Test")
  .setTitle("Menu dialog");
  dialogBuilder.create().show();*/
  return true;

//  finish();
 }
 return super.onKeyDown(keycode,event);  
}
Bay
  • 467
  • 7
  • 22
0

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>
Analizer
  • 1,594
  • 16
  • 30