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