I am trying to add an option menu in actionbar to my existing app but it is not working. If I create a new project with "hello world" default app I can see the button in action bar. The onCreateOptionMenu() method seems never caught in debug with breakpoint, what's wrong ??
I'm working with API 14 on both app and this is my MainActivity code.
import android.app.Activity;
import android.os.Bundle;
import android.view.Menu;
public class Principale extends Activity {
/** Called when the activity is first created. */
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.ecran_d_acceuil);
}
public boolean onCreateOptionMenu(Menu menu) {
getMenuInflater().inflate(R.menu.principale, menu);
return true;
}
}
My menu.xml code
<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"/>
</menu>
manifest.xml
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.example.myapp"
android:versionCode="1"
android:versionName="1.0" >
<uses-sdk
android:minSdkVersion="14"
android:targetSdkVersion="14" />
<uses-permission android:name="android.permission.INTERNET" />
<uses-permission android:name="android.permission.ACCESS_FINE_LOCATION" />
<uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION" />
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
<uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE" />
<application
android:allowBackup="true"
android:icon="@drawable/ic_launcher"
android:label="@string/app_name"
android:theme="@style/AppTheme" >
<activity
android:name="com.example.myapp.Principale"
android:label="@string/app_name" >
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<activity
android:name="com.example.myapp.Home"
android:label="@string/title_activity_home" >
</activity>
<activity
android:name="com.example.myapp.ListDir"
android:label="@string/title_activity_list_dir" >
</activity>
</application>
</manifest>
In my case, what fixed the issue, was the answer of this question; to remove
android:theme="@style/AppTheme"
from the tag in the Manifest.
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