标签未显示在操作栏中

时间:2017-04-27 10:35:09

标签: android android-actionbar

我的应用主题是:

<!-- Base application theme. -->
<style name="AppTheme" parent="Theme.AppCompat.Light.NoActionBar">
    <!-- Customize your theme here. -->
    <item name="colorPrimary">@color/colorPrimary</item>
    <item name="colorPrimaryDark">@color/colorPrimaryDark</item>
    <item name="colorAccent">@color/colorAccent</item>
    <item name="android:windowBackground">@color/background</item>
</style>

表示没有操作栏。但我希望活动只有一个操作栏但没有状态栏,所以我为该活动创建了一个样式:

<style name="chapter_theme" parent="Theme.AppCompat.Light.DarkActionBar">
    <item name="colorPrimary">@color/background</item>
    <item name="colorAccent">@color/colorAccent</item>
    <item name="android:windowBackground">@color/background</item>
</style>

清单文件:

 <activity
        android:name=".ChapterOne"
        android:theme="@style/chapter_theme"
        android:label="Chapter One">

    </activity>

为了摆脱状态栏,我在该活动的java文件中添加了以下代码:

 // To remove status bar
    requestWindowFeature(Window.FEATURE_NO_TITLE);
    getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN,
            WindowManager.LayoutParams.FLAG_FULLSCREEN);

    setContentView(R.layout.activity_chapter_one);

无法弄清楚出了什么问题

编辑:我知道错了。动作栏和标题的颜色是白色的,所以没有人能看到那里写的标题。我更改了操作栏的背景颜色。

现在我想知道如何更改标题的颜色?

1 个答案:

答案 0 :(得分:0)

尝试使用此标签添加标签

    ActionBar actionBar = getSupportActionBar();
     if (actionBar != null) {
        actionBar.setTitle("put your label here");

    }
相关问题