I am trying to create menu option in my test application.
I am able to see the menu when I set the theme in manifest to just default (The menu shows up in the top). If I set the theme in manifest to NoTitleBar. I can't see the menu option?
I want to get the menu when I set theme "NoTitleBar" in manifest.
How to fix it?
Below are things that I have used in my test application:
with Manifest:
<uses-sdk
android:minSdkVersion="8"
android:targetSdkVersion="17" />
<application
android:allowBackup="true"
android:icon="@drawable/ic_launcher"
android:label="@string/app_name"
android:theme="@android:style/Theme.NoTitleBar" >
<activity
android:name="com.ssn.menuoptions.MainActivity"
android:label="@string/app_name" >
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
</application>
</manifest>
And
Menu.xml
<?xml version="1.0" encoding="utf-8"?>
<menu xmlns:android="http://schemas.android.com/apk/res/android">
<item android:id="@+id/menu_preferences"
android:title="Preferences" />
</menu>
Java file:
@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);
return true;
}
Is it possible to get something like this:
How do I make menu to show up down?
Thanks!
Add following code below Activity.setContentView();
setContentView(R.layout.activity_detail);
// set option menu if has no hardware menu key
boolean hasMenu = ViewConfiguration.get(this).hasPermanentMenuKey();
if(!hasMenu){
//getWindow().setFlags(0x08000000, 0x08000000);
try {
getWindow().addFlags(WindowManager.LayoutParams.class.getField("FLAG_NEEDS_MENU_KEY").getInt(null));
}
catch (NoSuchFieldException e) {
// Ignore since this field won't exist in most versions of Android
}
catch (IllegalAccessException e) {
Log.w("Optionmenus", "Could not access FLAG_NEEDS_MENU_KEY in addLegacyOverflowButton()", e);
}
}
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