简体   繁体   中英

Android ActionBar isn't created

I'm currently working on a mp3 library on Android. Thing is, there are 4 tab, representing Songs, Albums, Artists and Playlists. My main activity creates a tabspec for each tab and add them to a tabhost. The problem is, I can't use the ActionBar. I tried the tutorial from Android Developpers and it works fine, however when I try to apply it on my project it doesn't work. I can't see the actionbar and if I try a getActionBar() in my activity it returns null.

As in the tutorial I put this code in the activity :

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

And I created this menu :

<?xml version="1.0" encoding="utf-8"?>

<menu xmlns:android="http://schemas.android.com/apk/res/android">
    <item android:id="@+id/menu_save"
          android:title="Hello !"
          android:showAsAction="ifRoom" />
</menu>

I suppose there are more things to do in order to display the actionbar, yet I can't find an accurate on the Web since now ... Does this have something to do with the xml from my main activity ?

Thanks for your attention

For me I added this to my manifest:

android:theme="@android:style/Theme.Holo.Light.DarkActionBar" >

Hopefully that saves some time from having to look it up.

The action bar is only available from Android 3.0 and above, and you need to set your application theme to Holo.

Besides setting the sdk version, for instance:

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

You also have to make the application theme use Holo .

使android:minSdkVersion="14"对我android:minSdkVersion="14"

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM