Question

menu bar is showing in virtual Device manger.when i try to open same app in my mobile is not showing menu bar Which has three Vertical dots.Any suggestion Please

MainActivity.java

package com.example.helloworld;

import android.os.Bundle;
import android.app.Activity;
import android.util.Log;
import android.view.Menu;

public class MainActivity extends Activity {
    public static String tag="Lifecycle activity";

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        Log.v(tag,"from oncreate function");
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
    }

    @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;
    }

}

(menu)main.xml

<menu xmlns:android="http://schemas.android.com/apk/res/android" >

    <item
        android:id="@+id/action_settings"
        android:orderInCategory="100"
        android:showAsAction="never"
        android:title="@string/action_settings"/>
       <item
        android:id="@+id/action_settings1"
        android:orderInCategory="100"
        android:showAsAction="never"
        android:title="@string/action_settings1"/>
           <item
        android:id="@+id/action_settings2"
        android:orderInCategory="100"
        android:showAsAction="never"
        android:title="@string/action_settings2"/>

</menu>

AndroidMainfest.xml

<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
    package="com.example.helloworld"
    android:versionCode="1"
    android:versionName="1.0" >

    <uses-sdk
        android:minSdkVersion="8"
        android:targetSdkVersion="12" />

    <application
        android:allowBackup="true"
        android:icon="@drawable/ic_launcher"
        android:label="@string/app_name"
        android:theme="@style/AppTheme" >
        <activity
            android:name="com.example.helloworld.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>
Was it helpful?

Solution

Add this code in onCreate method of those activities in which you want to show menu bar-

try {
            ViewConfiguration config = ViewConfiguration.get(this);
            Field menuKeyField = ViewConfiguration.class.getDeclaredField("sHasPermanentMenuKey");
            if(menuKeyField != null) {
                menuKeyField.setAccessible(true);
                menuKeyField.setBoolean(config, false);
            }
    } catch (Exception ex) {
            // Ignore
} 

OTHER TIPS

If a menu is displayed in the emulator, then it will also show up on the real device. But the thing is based on the Device that you hold, you might wanna find the way to access your menu in that. Cos some real devices have hard buttons for "Home", "Back" and "Menu" and some have soft touch buttons. But certain devices like HTC One X and others have menu displayed as the 3 dots you mentioned.

Replace your (menu)main.xml by following code

<menu xmlns:android="http://schemas.android.com/apk/res/android" >

    <item
        android:id="@+id/action_settings"
        android:orderInCategory="100"
        android:showAsAction="ifRoom"
        android:title="@string/action_settings"/>
       <item
        android:id="@+id/action_settings1"
        android:orderInCategory="100"
        android:showAsAction="ifRoom"
        android:title="@string/action_settings1"/>
           <item
        android:id="@+id/action_settings2"
        android:orderInCategory="100"
        android:showAsAction="ifRoom"
        android:title="@string/action_settings2"/>

</menu>

I would like to suggest this to try and see for Android missing MENU button.

Scenario 1: App does not use standard title bar but have menu options

If you have a app (Android api level < 11) with MENU options but you are hiding the the title bar either to support your own toolbar or your app needs to be full screen, and you want it to work fine on devices like Galaxy Nexus which do not have h/w MENU button, then make sure ‘targetSDKVersion’ is set to less than 11 or better don't set it if you don't need to.

<manifest xmlns:android="http://schemas.android.com/apk/res/android" package="com.quicknotes.views" android:versioncode="26" android:versionname="@string/app_version">
    <uses-sdk android:minsdkversion="3" android:targetsdkversion="10">
    </uses-sdk>
</manifest>

Once done your application should see a three dotted overflow menu button at the bottom navigation bar.

Scenario 2: App does use standard title bar and have menu options

If you have a app (Android api level < 11) with standard title bar and using menu options, and you want to make it work fine on new devices which support Action bar, then make sure ‘targetSDKVersion’ is set to 11 or higher.

This is generally set to enable some features by default. Like your legacy app uses legacy title bar and standard MENU options so setting ‘targetSdkVersion’ to ’11′ will enable Holo theme if you are NOT setting it in your app and also will enable Action bar. Here you don't have to worry about no h/w MENU button as overflow menu button will be shown in the Action bar.

For more information use this link.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top