【问题标题】:Why is my Custom Action Bar White, and not the Specified Color?为什么我的自定义操作栏是白色的,而不是指定的颜色?
【发布时间】:2016-08-15 20:48:37
【问题描述】:

我正在创建一个 Android 应用,并且我使用此代码自定义了我的操作栏-

action_bar_styles.xml

<resources>

<!-- Base application theme. -->
<style name="AppTheme" parent="Theme.AppCompat.Light.NoActionBar">
</style>

<style name="Theme.Base" parent="AppTheme">
    <item name="android:textColorPrimary">#f1f1f1</item>
    <item name="colorPrimary">@color/notesPrimaryBackgroundColor</item>
    <item name="colorPrimaryDark">@color/notesSecondaryBackgroundColor</item>
    <item name="colorAccent">@color/notesColorBackgroundAccent</item>
    <item name="windowActionBar">true</item>
    <item name="android:windowNoTitle">false</item>
    <item name="android:windowBackground">@color/notesBackgroundColor</item>
</style>

</resources>

colors.xml

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

<resources>
<color name="notesPrimaryBackgroundColor">#009688</color>
<color name="notesSecondaryBackgroundColor">#004D40</color>
<color name="notesColorBackgroundAccent">#FF9922</color>
<color name="notesBackgroundColor">#FAFAFA</color>
<color name="notesPrimaryTextColor">#FAFAFA</color>
<color name="notesBody">#FAFAFA</color>
<color name="notesCardBody">#EBEBEB</color>
<color name="notesSecondaryTextColor">#656565</color>
<color name="notesDropBoxSeparator">#C1C1C1</color>
<color name="notesSelectionTickColor">#455EDE</color>
<color name="notesImageBackground">#C1C1C1</color>
</resources>

我在 Android Manifest 中选择了 Theme.Base 作为主题,并且操作栏颜色显示在设计器中,但是当我在三星平板电脑上运行我的应用程序时,操作栏是白色的,其他一切正常。这可能是因为我在其他地方也指定了操作栏颜色,还是因为我没有正确指定它的颜色?还有其他想法吗?

【问题讨论】:

    标签: android xml colors android-actionbar


    【解决方案1】:

    更新代码

    <style name="Theme.Base" parent="Theme.AppCompat.Light">
    

    希望对您有所帮助。

    指定

    <style name="AppTheme" parent="Theme.AppCompat.Light.NoActionBar"></style>
    

    你让这个家伙成为你的应用主题的父级,这反过来又迫使它没有操作栏。

    【讨论】:

    • 我更新了我的代码,现在操作栏确实显示了,但它的正上方是一个白条。想法?
    【解决方案2】:

    酷。当然,乔治,那是状态栏的东西。如果您的测试设备 API 版本 > 21,它将显示为 colorPrimaryDark 值。如果不是你必须手动设置。

    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
        getWindow().addFlags(WindowManager.LayoutParams.FLAG_DRAWS_SYSTEM_BAR_BACKGROUNDS);
        getWindow().setStatusBarColor(getResources().getColor(R.color.actionbar));
    }
    

    Helpful notes.

    【讨论】:

    • 实际上是 'truefalse' 使那个带有标题的白条在其中出现。你确实解决了我的问题。谢谢!
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2014-06-02
    • 1970-01-01
    • 2015-02-25
    • 1970-01-01
    • 2012-11-23
    • 1970-01-01
    相关资源
    最近更新 更多