Three-point action overflow menu in action bar?

enter image description here I noticed that in my application, when I add a menu for new devices that do not have a hardware menu button, it adds three dots to the action bar. However, in some applications, I see that you can transfer these three points to the bottom (in the software navigation). How can this be achieved? I also use actionbarsherlock if that matters.

+4
source share
2 answers

You can β€œachieve” this by setting targetSdk below 14. I say β€œachieve” because it is bad practice. For devices with soft keys, while you use a theme with an ActionBar, it displays a menu in the ActionBar. If you use a theme without an ActionBar (non-Holo), it will display three dots.

Three points hate.
Three points are evil. Three points should. be. uprooted.

In short, I would avoid this. :)

See also: Shame menu button

+7
source

So, it turns out pretty simple, I recently implemented it in my application.

Items to be displayed in the overflow menu insert them into one menu item as follows:

 <menu xmlns:android="http://schemas.android.com/apk/res/android" > <item android:id="@+id/empty" android:orderInCategory="101" android:showAsAction="always" android:icon="@drawable/ic_action_overflow"> <menu> <item android:id="@+id/action_settings" android:orderInCategory="96" android:showAsAction="never" android:title="@string/menu_settings" android:icon="@drawable/ic_action_settings"/> <item android:id="@+id/action_share" android:orderInCategory="97" android:showAsAction="never" android:title="@string/menu_share" android:icon="@drawable/ic_action_share"/> <item android:id="@+id/action_rate" android:orderInCategory="98" android:showAsAction="never" android:title="@string/menu_rate" android:icon="@drawable/ic_action_important"/> <item android:id="@+id/action_feedback" android:orderInCategory="99" android:showAsAction="never" android:title="@string/menu_feedback" android:icon="@drawable/ic_action_edit"/> </menu> </item> </menu> 

Now edit the main activity file as follows:

 package com.example.test; //all your import statements go here Menu mainMenu=null; @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); } @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); mainMenu=menu; return true; } //Menu press should open 3 dot menu @Override public boolean onKeyDown(int keyCode, KeyEvent event) { if (keyCode==KeyEvent.KEYCODE_MENU) { mainMenu.performIdentifierAction(R.id.empty, 0); return true; } return super.onKeyDown(keyCode, event); } 
+1
source

Source: https://habr.com/ru/post/1442388/


All Articles