Question

In my app I want to use an activity without titelbar or actionbar. I solved this with:

<activity
    android:name="com.cilenco.lockscreen.Position"
    android:label="@string/title_activity_position" 
    android:theme="@android:style/Theme.Light.NoTitleBar" >
    <intent-filter> 
        <action android:name="com.cilenco.lockscreen.Position" /> 
        <category android:name="android.intent.category.DEFAULT" />  
    </intent-filter>
</activity>

My problem now is that I have to use an option menu and if I run my app on a device without hardware keys I can not open the option menu. I thought I will the Button with 3 dots (Overflow menu) in the bar where the back and home key is but it is not visible. What can I do to open the option menu on devices without hardware keys?

Was it helpful?

Solution

There is a function openOptionsMenu() that you could call
manually in your activity when you want to open the menu.

public void openMenu()
{
    openOptionsMenu();
}

Better:
if you want the 3 dot overflow button in the navigation bar
just create your optionsMenu as usual:

@Override
public boolean onCreateOptionsMenu(Menu menu)
{
    //add your menu
}

@Override
public boolean onOptionsItemSelected(MenuItem item)
{
    //select what happens when you click at an item

    return true;
}

and make sure to set both minSdkVersion and targetSdkVersion to "10" or lower!
For example:

<manifest xmlns:android="http://schemas.android.com/apk/res/android" package="your.package.name">
    <uses-sdk android:minsdkversion="4" android:targetsdkversion="10" />
</manifest>
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top