【发布时间】:2020-02-10 06:38:48
【问题描述】:
我想自定义我的 ActionBar。我的主题如下所示:
<style name="AppTheme" parent="Theme.MaterialComponents.DayNight">
<item name="actionBarStyle">@style/MyActionBar</item>
</style>
<style name="MyActionBar" parent="@style/ThemeOverlay.MaterialComponents.ActionBar">
<item name="background">@drawable/actionBarBackground</item>
</style>
在值文件夹中:
<drawable name="actionBarBackground">#FFFFFFFF</drawable>
在 values-night 文件夹中:
<drawable name="actionBarBackground">#FF000000</drawable>
不知道为什么我的 ActionBar 背景颜色没有相应改变。我也尝试以不同的其他方式改变我的主题,但没有任何效果。这是我的其他尝试:
我用actionBarTheme代替了actionBarStyle。
<item name="actionBarTheme">@style/MyActionBar</item>
我也尝试过使用colorPrimary。
<item name="colorPrimary">@color/actionBarBackground</item>
我错过了什么吗?
【问题讨论】:
-
这可能是因为您已将颜色声明为可绘制,它们不是同一个概念。
-
我也试过颜色,但还是同样的问题。
-
您使用的是操作栏还是工具栏?
-
我的Activity的布局文件什么都没有。由于我的主题是 Theme.MaterialComponents.DayNight,它默认包含一个 ActionBar。
标签: android android-layout android-actionbar material-components-android material-components