简体   繁体   English

未创建Android ActionBar

[英]Android ActionBar isn't created

I'm currently working on a mp3 library on Android. 我目前正在使用Android上的mp3库。 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. 我的主要活动是为每个标签创建一个tabspec并将它们添加到tabhost。 The problem is, I can't use the ActionBar. 问题是,我无法使用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. 我尝试了来自Android Developpers的教程,并且效果很好,但是当我尝试将其应用到我的项目中时,它将无法正常工作。 I can't see the actionbar and if I try a getActionBar() in my activity it returns null. 我看不到操作栏,如果我在活动中尝试使用getActionBar(),它将返回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 ? 我想还需要做更多的事情来显示操作栏,但是自从现在以来,我在Web上找不到准确的信息……这与我的主要活动中的xml有关吗?

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. 操作栏仅在Android 3.0及更高版本中可用,并且您需要将应用程序主题设置为Holo。

Besides setting the sdk version, for instance: 除了设置sdk版本,例如:

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

You also have to make the application theme use Holo . 您还必须使应用程序主题使用Holo

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

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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