【问题标题】:How to change ActionBar Color on AppCompat如何在 AppCompat 上更改 ActionBar 颜色
【发布时间】:2015-06-02 19:13:54
【问题描述】:

我想知道如何更改 AppCompat 主题的操作栏背景颜色。我的样式文件代码如下

价值观/风格

<resources>

    <!--
        Base application theme, dependent on API level. This theme is replaced
        by AppBaseTheme from res/values-vXX/styles.xml on newer devices.
    -->
    <style name="AppBaseTheme" parent="Theme.AppCompat.Light">
        <!--
            Theme customizations available in newer API levels can go in
            res/values-vXX/styles.xml, while customizations related to
            backward-compatibility can go here.
        -->
    </style>

    <!-- Application theme. -->
    <style name="AppTheme" parent="AppBaseTheme">
        <!-- All customizations that are NOT specific to a particular API-level can go here. -->
    </style>

</resources>

价值观-V11

<resources>

    <!--
        Base application theme for API 11+. This theme completely replaces
        AppBaseTheme from res/values/styles.xml on API 11+ devices.
    -->
    <style name="AppBaseTheme" parent="Theme.AppCompat.Light">
        <!-- API 11 theme customizations can go here. -->
    </style>

</resources>

Values-v14
<resources>

    <!--
        Base application theme for API 14+. This theme completely replaces
        AppBaseTheme from BOTH res/values/styles.xml and
        res/values-v11/styles.xml on API 14+ devices.
    -->
    <style name="AppBaseTheme" parent="Theme.AppCompat.Light.DarkActionBar">
        <!-- API 14 theme customizations can go here. -->
    </style>


</resources>

【问题讨论】:

    标签: android colors android-actionbar background-color android-appcompat


    【解决方案1】:

    android 解释了如何做到这一点 http://developer.android.com/training/basics/actionbar/styling.html

    <?xml version="1.0" encoding="utf-8"?>
    <resources>
        <!-- the theme applied to the application or activity -->
        <style name="CustomActionBarTheme"
               parent="@style/Theme.AppCompat.Light.DarkActionBar">
            <item name="android:actionBarStyle">@style/MyActionBar</item>
    
            <!-- Support library compatibility -->
            <item name="actionBarStyle">@style/MyActionBar</item>
        </style>
    
        <!-- ActionBar styles -->
        <style name="MyActionBar"
               parent="@style/Widget.AppCompat.Light.ActionBar.Solid.Inverse">
            <item name="android:background">@drawable/actionbar_background</item>
    
            <!-- Support library compatibility -->
            <item name="background">@drawable/actionbar_background</item>
        </style>
    </resources>
    

    然后将清单中的主题更改为您在上面编写的主题

    【讨论】:

    • 虽然链接很好,但请在您的回答中回答问题。不要只提供第三方网站的链接。
    【解决方案2】:

    您应该可以在AppTheme 中定义colorPrimary

    <style name="AppTheme" parent="AppBaseTheme">
        <item name="colorPrimary">#3f51b5</item>
    </style>
    

    【讨论】:

      猜你喜欢
      • 2017-07-08
      • 1970-01-01
      • 2014-05-04
      • 1970-01-01
      • 2015-01-08
      • 2014-07-22
      • 2016-12-11
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多