I noticed that in my app when I add a menu for new devices that dont have a hardware menu button it adds the three dots to the actionbar. However, I see on some apps that you can actually move those three dots to the bottom (on the software navigation) How can this be achieved? I am using actionbarsherlock as well if that makes a difference.
You can "achieve" this by setting your targetSdk
below 14. I say "achieve", because this is bad practice. For devices that have software keys, as long as you're using a theme with the ActionBar, it will display the menu on the ActionBar. If you're using a theme without the ActionBar (non-Holo), it will display the three dots.
The three dots are hated.
The three dots are evil.
The three dots must. be. eradicated.
In short, I'd avoid it. :)
See also: Menu Button of Shame
So, turns out it's pretty simple, I recently implemented in my app.
The items that need to be shown in the overflow menu, nest them under 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); }
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With