Android ActionBar 不改变背景颜色

标签 android background android-actionbar themes android-actionbar-compat

我想改变我的操作栏的背景颜色,但它没有改变。我的应用正在使用 AppCompat 主题(如果有影响的话)。

这是我正在使用的主题。我的应用程序指向使用这个主题,所以这不是问题

<!-- Base application theme. -->
<style name="AppTheme" parent="Theme.AppCompat.Light">
    <item name="actionBarStyle">@style/ActionBar</item>
</style>

<!-- Action Bar Styles -->
<style name="ActionBar" parent="Widget.AppCompat.ActionBar">
    <item name="android:background">@color/blue</item>
    <item name="background">@color/blue</item>
</style>

最佳答案

在你的ActionBar样式中,删除android:background,只保留background属性。还要确保在 AndroidManifest.xml 文件中的应用程序标记或扩展操作栏的 Activity 中实现您的 AppTheme。我还在 Widget.AppCompat 之前添加了“@style/”属性,因为它是 android 库中定义的默认样式。

您的代码应如下所示:

<!-- Base application theme. -->
<style name="AppTheme" parent="Theme.AppCompat.Light">
    <item name="actionBarStyle">@style/ActionBar</item>
</style>

<!-- Action Bar Styles -->
<style name="ActionBar" parent="@style/Widget.AppCompat.ActionBar">
    <item name="background">#0000ff</item>
</style>

关于Android ActionBar 不改变背景颜色,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/25613342/

相关文章:

java - ANDROID 空指针异常错误

swift - 在后台运行一个任务,在 Swift/iOS8 中从 MPMedia 框架切换歌曲长达 100 分钟

android - 仅接收来自 GCM 的最后一个后台静默推送通知

android - 在不增加 session 数的情况下跟踪 Android 中的后台事件的好方法是什么?

Android 操作栏可检查菜单项无法正常工作/显示?

android - 无法解析 : com. google.firebase :firebase-core:11. 0.0

java - addValueChangeListener 不会在 android 中触发

java - Picasso - 自定义 RequestHandler 不会在磁盘上缓存图像

android - 为什么安卓:actionBarDivider doesn't work?

android - 操作栏搜索 View (Android) 空错误