android - ActionBar 不显示

标签 android

我使用 TabHostTabSpec 在 android 中创建了一个包含三个选项卡的项目。我扩展了我的
TabActivity 的主要 Activity 问题是 ActionBar 没有显示在应用程序上。我使用了 Holo.Light.DarkActionBar 主题。

主 Activity .java

     public class MainActivity extends TabActivity {

    TabHost tabhost;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_main);


    tabhost=getTabHost();

    TabHost.TabSpec homespec=tabhost.newTabSpec("Home");
    homespec.setIndicator("Home",null);
    Intent homeintent=new Intent(this,HomeActivity.class);
    homespec.setContent(homeintent);

    TabHost.TabSpec eventspec=tabhost.newTabSpec("Event");
    eventspec.setIndicator("Event");
    Intent eventintent=new Intent(this,EventActivity.class);
    eventspec.setContent(eventintent);

    TabHost.TabSpec profilespec=tabhost.newTabSpec("Profile");
    profilespec.setIndicator("Profile");
    Intent profileintent=new Intent(this,ProfileActivity.class);
    profilespec.setContent(profileintent);

    tabhost.addTab(homespec);
    tabhost.addTab(eventspec);
    tabhost.addTab(profilespec);
    }
    }

activity_main.xml `

<TabHost
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:id="@android:id/tabhost"
    android:layout_weight="1">

    <LinearLayout
        android:layout_width="fill_parent"
        android:layout_height="fill_parent"
        android:orientation="vertical">

        <TabWidget
            android:id="@android:id/tabs"
            android:layout_width="fill_parent"
            android:layout_height="wrap_content"/>

        <FrameLayout
            android:id="@android:id/tabcontent"
            android:layout_width="fill_parent"
            android:layout_height="fill_parent">

            <LinearLayout
                android:id="@+id/tab1"
                android:layout_width="fill_parent"
                android:layout_height="fill_parent"
                android:orientation="vertical"
                />

            <LinearLayout
                android:id="@+id/tab2"
                android:layout_width="fill_parent"
                android:layout_height="fill_parent"
                android:orientation="vertical"/>

            <LinearLayout
                android:id="@+id/tab3"
                android:layout_width="fill_parent"
                android:layout_height="fill_parent"
                android:orientation="vertical"/>
        </FrameLayout>
    </LinearLayout>
</TabHost>

有没有其他方法可以实现这个也建议我?

最佳答案

在 AndroidManifest.xml 中为此 Activity 设置主题:

<activity android:name=".MainActivity"
            android:theme="@android:style/Theme.Holo.Light"/>

转到 activity_main 并点击设计 -> 主题(在顶部栏中,在设备名称和景观旁边)-> list 主题 -> 然后选择您的主题。

编辑: 当然加上这个(如果你不是故意忘记的)

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

关于android - ActionBar 不显示,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/27862812/

相关文章:

java - 我如何知道 View 是否已绘制

android - 带有 JQM for android 的 Phonegap 中的字符串值配置文件

android - 图像在图像加载器中被复制

java - 在 android studio 中突出显示输入文本

android - 如何从资源文件夹获取字体文件的路径以及如何使用该路径在xamarin android中设置SKTypeface?

java - Handler 在运行线程时做什么?

android - 如何自定义微调器的下拉菜单?

android - 如何在设备管理员停用时删除 Android 设备?

android - & 符号 list 文件( Intent 过滤器)

安卓NDK : calling java method from JNI C class