Action bar - menu button - missing

I managed to confuse one of my Android projects by deleting something (I suspect). Below are my manifests and menu resources. For some reason, my action bar does not display a menu button when the application starts.

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

However, when starting the application, the menu / parameter button is not created. Any idea?

Change 1

After some serious testing, I found that adding localization support to my application caused this problem.

I deleted all the localized values ​​- * directories and returned the action bar, then copied the values ​​directory to -en values ​​and launched it on my English device. Then the action bar disappeared. Is this the light for anyone?

+4
source share
4 answers

Well, they found out what caused the problem, and I probably did not provide enough information in my original post if someone had previously encountered this problem.

The fatal mistake I made was

 cp -r res/values res/value-en 

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

Removing it and having only the styles.xml in the res/values and res/values-v* directory fixes the problem.

+6
source

The overflow menu button only appears on the action bar on devices that do not have a MENU button on the screen. Try pressing the MENU button on the device or emulator.

+11
source

I think your onCreateOptionsMenu problem is MenuInflater , change it to the following and see if this works for you:

 public boolean onCreateOptionsMenu(Menu menu) { MenuInflater inflater = getMenuInflater(); inflater.inflate(R.menu.activity, menu); return true; } 
0
source
  android:showAsAction="never" 

Change this line to:

  android:showAsAction="ifRoom" 
0
source

Source: https://habr.com/ru/post/1432970/


All Articles