Wildchild7 Wildchild7 - 6 months ago 35
Android Question

Android actionbar not visible

i am trying to add an option menu in actionbar to my existing app but still not working... Intsead of if i make 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>

Answer

Have you tried to set the app theme to a theme that supports the ActionBar, like Theme.Holo.Light?

Also, in your Activity you can try getActionBar().show();.

Comments