【问题标题】:Changing the colour of ActionBar in Android在 Android 中更改 ActionBar 的颜色
【发布时间】:2015-04-02 09:34:28
【问题描述】:

这是我在 styles.xml 中的 xml 代码,用于更改 ActionBar 的主题和颜色。

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

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

<!-- ActionBar styles -->
<style name="MyActionBar"
    parent="Widget.AppCompat.Light.ActionBar.Solid.Inverse">
    <item name="android:icon">@drawable/brand_logo</item>
    <item name="android:background">#ff5d44</item>
</style>

这里是documentation。我的应用支持 API 级别 11 及更高级别。不知道我哪里出错了。请帮忙。

【问题讨论】:

  • 试试&lt;item name="actionBarStyle"&gt;@style/MyActionBar&lt;/item&gt;@Narayanarao
  • 试过了,但操作栏没有变化。
  • 你在使用toolbar吗? @Narayanarao
  • 设置&lt;item name="colorPrimary"&gt;@color/YourColor&lt;/item&gt;@Narayanarao
  • 对不起,操作栏和工具栏有什么区别?

标签: android android-layout android-actionbar android-theme


【解决方案1】:

将“AppTheme”设置为应用程序/活动的主题。

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

</style>

更多信息请查看THIS、THIS 和THIS

【讨论】:

  • 这会删除现有的操作栏。
  • @Anirudh 怎么可能是NoActionBar?
  • @Anirudh 他没有要求Holo 主题。
  • @NarayanaraoR 请检查我的新分析器,看看它是否有帮助
  • 这会引发错误。 “您需要在此活动中使用 Theme.AppCompat 主题(或后代)。”
【解决方案2】:

我正在使用支持库。所以这里是修复。

<style name="MyActionBar"
        parent="@style/Widget.AppCompat.Light.ActionBar.Solid.Inverse">
        <item name="android:background">#ff5d44</item>
        <item name="android:titleTextStyle">@style/MyActionBarTitleText</item>

         <!--Support library compatibility-->
        <item name="background">@color/orange</item>
        <item name="titleTextStyle">@style/MyActionBarTitleText</item>
    </style>

【讨论】:

  • 很奇怪你写了一个关于操作栏背景颜色的问题,你检查你的答案是正确的,而不是最好的答案。当前的 appCompat (v21) 使用@Anirudh 报告的答案。
猜你喜欢
  • 1970-01-01
  • 2014-07-22
  • 1970-01-01
  • 2015-07-25
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多