4

I have managed to mess up one my Android projects, by removing something (i suspect). Below are my manifests and menu resource's. For some reason my action bar is not displaying the menu button when I run the application.

<menu xmlns:android="http://schemas.android.com/apk/res/android">
<item android:id="@+id/menu_settings"
    android:title="@string/menu_settings"
    android:orderInCategory="100"
    android:showAsAction="never" />
</menu>

Manifest:

<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.myapp"
android:versionCode="6"
android:versionName="2.1.0" >

<uses-permission android:name="android.permission.WRITE_SETTINGS"/>
<uses-permission android:name="android.permission.INTERNET"/>
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE"/>

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

<application
    android:icon="@drawable/ic_launcher"
    android:label="@string/app_name"
    android:theme="@style/AppTheme" >
    <activity
        android:name=".MyActivity"
        android:label="@string/title_activity" 
        android:screenOrientation="portrait">
        <intent-filter>
            <action android:name="android.intent.action.MAIN" />

            <category android:name="android.intent.category.LAUNCHER" />
        </intent-filter>
    </activity>
</application>

</manifest>

I also have this in my Activity code

    @Override
public boolean onCreateOptionsMenu(Menu menu) {
    getMenuInflater().inflate(R.menu.activity, menu);
    return true;
}

@Override
public boolean onOptionsItemSelected(MenuItem item) {
    // Handle item selection
    switch (item.getItemId()) {
        case R.id.menu_settings:
            return true;
        default:
            return super.onOptionsItemSelected(item);
    }
}

But still no menu/option button is created when the application runs. Any idea's?

Edit 1

After some major trial an error i have discovered that adding localization support to my application has caused the issue.

I removed the all localized values-* directories and the Action Bar came back, i then copied the values directory to values-en and ran it on my English device. The action bar then disappeared. Does this shed any light for anyone?

Ne0
  • 2,688
  • 3
  • 35
  • 49
  • I didn't mean to delete my last comment. It sounds like your issue is with this line `android:showAsAction="never"` – jnthnjns Sep 07 '12 at 15:13
  • I thought the same thing, checked it against a project with the same menu resource file and that project shows it fine. I have tried with `android:showAsAction="always"` yet still nothing gets shown. – Ne0 Sep 07 '12 at 15:15
  • I've never used `never`, that's odd. Mine always reads `android:showAsAction="ifRoom|withText"` – jnthnjns Sep 07 '12 at 15:23

4 Answers4

11

The on-screen overflow menu button only appears in the action bar on devices that lack an off-screen MENU button. Try pressing the MENU button on your device or emulator.

CommonsWare
  • 986,068
  • 189
  • 2,389
  • 2,491
  • on Genymotion, you can press Ctrl+M to bring up menu. – ir-tech Apr 13 '17 at 18:03
  • Does this work for AndroidTV? See my question https://stackoverflow.com/questions/65296436/alternative-for-missing-app-bar-in-android-tv –  Dec 14 '20 at 21:18
  • @MostowskiCollapse: This question, and most of the answers, are from 2012. Little of this is relevant in modern Android, and I do not know off the top of my head how the action bar behaves on current editions of Android TV. Sorry! – CommonsWare Dec 14 '20 at 21:54
  • Yes indeed, this was quite some time ago. –  Dec 15 '20 at 11:23
6

Ok, found out what was causing the issue and I probably hadn't provided enough info in my original post if someone had previously come across this issue.

The fatal mistake i had made was

cp -r res/values res/value-en

I did this for all the locales, this also copied the styles.xml file. Having this in the directory caused this very annoying headache!

Removing it and only having the styles.xml file in the res/values directory and res/values-v* directories fixed the issue.

Ne0
  • 2,688
  • 3
  • 35
  • 49
0

I think your onCreateOptionsMenu - MenuInflater is the issue, change to the following and see if that works for you:

public boolean onCreateOptionsMenu(Menu menu) {
    MenuInflater inflater = getMenuInflater();
    inflater.inflate(R.menu.activity, menu);
    return true;
}
jnthnjns
  • 8,962
  • 4
  • 42
  • 65
  • Thanks, I have tested your code out of curiosity, but that code is the same as mine. Still no action bar! – Ne0 Sep 07 '12 at 15:23
  • Okay, this is curious. What if you change your `android:minSdkVersion="8"` to `android:minSdkVersion="11"` since `MenuInflator` was introduced in API 11 – jnthnjns Sep 07 '12 at 15:27
  • 2
    @Asok: `MenuInflater` was introduced in API Level 1, not 11. – CommonsWare Sep 07 '12 at 16:08
  • @CommonsWare Thank you, I'm sorry `ActionBar` is what I was thinking of. – jnthnjns Sep 07 '12 at 16:17
0
 android:showAsAction="never" 

Change this line to:

 android:showAsAction="ifRoom" 
Burhan ARAS
  • 2,517
  • 25
  • 19