Android dots elements in the form of three dots.

I have a menu for my main activity (res / menu / main_menu.xml), and I want only one item on the action bar, and the rest should be hidden at three points on the menu. Three dots menu

The problem is that I never see an element with three dots in the action bar. Why can't I see three points? How to make elements hide under it?

Note. I use minSdkVersion = "14" and I am testing in AVD.

+15
android android-actionbar menu android-4.0-ice-cream-sandwich
source share
5 answers
<?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/menu_item_share" android:title="@string/share" android:icon="@android:drawable/ic_menu_share" app:showAsAction="ifRoom" android:actionProviderClass="android.widget.ShareActionProvider" /> <item android:id="@+id/empty" android:title="@string/options" android:orderInCategory="101" app:showAsAction="always" android:icon="@drawable/baseline_more_vert_black"> <menu> <item android:id="@+id/action_settings" android:icon="@android:drawable/ic_menu_preferences" app:showAsAction="ifRoom" android:title="@string/settings" /> <item android:id="@+id/action_help" android:icon="@android:drawable/ic_menu_help" app:showAsAction="ifRoom" android:title="@string/help" /> </menu> </item> </menu> 

You will need to add the baseline_more_vert_black badges to the res/drawable... only you download them from here .

+29
source share

this solution provided by ban-geoengineering is very interesting ... The 3 dot icon sometimes doesn’t appear if you use the android namespace : showAsAction android: instead a custom namespace, for example:

 <menu xmlns:android="http://schemas.android.com/apk/res/android" xmlns:app="http://schemas.android.com/apk/res-auto"> <item android:id="@+id/taskNotificationsBtn" app:showAsAction="always" android:icon="@drawable/tasks"/> 

But the solution provided by ban-geoengineering helps me solve the problem of changing the direction of the ActionBar elements to fit the Arabic layout. I used the ActionBarRTLizer library, and the standard approach with android os 3dots causes some error when the menu item icons sometimes overlap (a very unpleasant situation), but this is a non-standard solution

 <item android:id="@+id/empty" android:title="@string/options" android:orderInCategory="101" android:showAsAction="always" android:icon="@drawable/ic_action_overflow"> <menu> <item android:id="@+id/action_settings" android:icon="@android:drawable/ic_menu_preferences" android:showAsAction="ifRoom" android:title="@string/settings" /> <item android:id="@+id/action_help" android:icon="@android:drawable/ic_menu_help" android:showAsAction="ifRoom" android:title="@string/help" /> </menu> </item> 

solved the problem and RTL works just fine! :)

This can also be useful if you want to handle hardware menu buttons:

 @Override public boolean onKeyUp(int keyCode, KeyEvent event) { if (keyCode == KeyEvent.KEYCODE_MENU) { // do stuff return true; } else { return super.onKeyUp(keyCode, event); } } 

and add here: mMenuReference.performIdentifierAction (R.id.menu_0, 1);

to replace the submenu displayed as the overflow menu, depending, for example, on the current activity, you can use this solution:

  public boolean onCreateOptionsMenu(Menu menu) { // Inflate your main_menu into the menu getMenuInflater().inflate(R.menu.main_menu, menu); // Find the menuItem to add your SubMenu MenuItem myMenuItem = menu.findItem(R.id.my_menu_item); // Inflating the sub_menu menu this way, will add its menu items // to the empty SubMenu you created in the xml getMenuInflater().inflate(R.menu.sub_menu, myMenuItem.getSubMenu()); } 
+5
source share

try it;

menu.xml

 <?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/menu_new_content_facebook" android:orderInCategory="100" android:title="@string/str_share_facebook" app:showAsAction="never" /> <item android:id="@+id/menu_new_content_twitter" android:orderInCategory="200" android:title="@string/str_share_twitter" app:showAsAction="never" /> </menu> 

MainActivity.java

  @Override public boolean onCreateOptionsMenu(Menu menu) { getMenuInflater().inflate(R.menu.menu, menu); return true; } @Override public boolean onOptionsItemSelected(MenuItem item) { int id = item.getItemId(); if(id == R.id.menu_new_content_twitter){ // do something } return super.onOptionsItemSelected(item); } 
+5
source share

Why can't I see an element with three dots?

Your emulator emulates a device with a MENU button. If the device has a MENU button, the MENU button causes overflow.

+2
source share

The solution can be found here https://stackoverflow.com/a/312616/2128 which worked fine for me. No need to work with xml-employees, this is done only programmatically.

 private void getOverflowMenu() { try { ViewConfiguration config = ViewConfiguration.get(this); Field menuKeyField = ViewConfiguration.class.getDeclaredField("sHasPermanentMenuKey"); if(menuKeyField != null) { menuKeyField.setAccessible(true); menuKeyField.setBoolean(config, false); } } catch (Exception e) { e.printStackTrace(); } } 
0
source share

All Articles