Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to add menu button on the navigation bar

I have a simple app which only needs a menu button with some options, and it should work in all devices.

Anyway, my app works fine in all cases, except for that I couldn't place menu button on the navigation bar. Here is my code:

styles.xml in value folder

<style name="AppTheme" parent="AppBaseTheme">
    <item name="android:windowNoTitle">true</item>        
</style>

styles.xml in value-v11 & value-v14 folders

<style name="AppTheme" parent="AppBaseTheme">
    <item name="android:windowNoTitle">false</item>
    <item name="android:windowActionBar">true</item>
    <item name="android:actionBarStyle">@android:style/Widget.Holo.ActionBar</item>        
</style>

This code appears in all onCreate events of my activities

if(Build.VERSION.SDK_INT <= 10 || (Build.VERSION.SDK_INT >= 14 &&    
ViewConfiguration.get(this).hasPermanentMenuKey()))
{
// menu key is present
ActionBar actionBar = getActionBar();
if(actionBar!=null)
actionBar.hide();
}
else
{
//No menu key
    ActionBar actionBar = getActionBar();
    if(actionBar!=null)
actionBar.show();
}

This code works fine, but in case I there isn't any action bar, I want to put the menu button in the navigation bar.

I've done so much googling for that, but I couldn't find any working solution for this.

Thanks in Advance.

like image 875
moji Avatar asked Oct 26 '13 08:10

moji


1 Answers

Since nobody had answered my question, I had to answer it my self.

First, it seems it is not recommended to activate the menu button in the navigation bar! (By Google)

Anyway, if you are interested in activating it, all you have to do is:

        1. Make a simple menu like before
        2. Not to use an action bar
        3. Set targetSdkVersion to 13 or below

And, it is highly recommended to read this article Say Goodbye To The Menu Button

like image 64
moji Avatar answered Sep 23 '22 19:09

moji