操作栏的颜色不随AppCompat V7的变化:21 [英] Action Bar color doesn't change with AppCompat v7:21

查看:118
本文介绍了操作栏的颜色不随AppCompat V7的变化:21的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

目前我想自定义背景色设置为一个操作栏上AppCompat V7:21。我试过很多可能性,到现在我也弄不清是怎么回事。

这是我的 RES /价值/ styles.xml

 <资源>

    <颜色名称=action_bar>#000< /彩色>

    <! - 基本应用主题。 - >
    <样式名称=AppTheme父=Theme.AppCompat.Light>
        <! - 自定义你的主题在这里。 - >
        <项目名称=actionBarStyle> @风格/ MyActionBar< /项目>

    < /风格>

    <! - 动作条的风格 - >
    <样式名称=MyActionBar父=Widget.AppCompat.Light.ActionBar>
        <项目名称=机器人:背景> @色/ action_bar< /项目>

    < /风格>

< /资源>
 

解决方案

我已经想通了!事实上,很多用户界面的东西上的API 21改变,等等AppCompat 7版。您可以设置 操作栏的颜色(其中包括)是这样的:

 <! - 延长的Theme.AppCompat主题之一 - >
<样式名称=Theme.MyTheme父=Theme.AppCompat.Light>
    <! - 自定义调色板 - >
    <项目名称=colorPrimary> @色/ material_blue_500< /项目>
    <项目名称=colorPrimaryDark> @色/ material_blue_700< /项目>
    <项目名称=colorAccent> @色/ material_green_A200< /项目>
< /风格>
 

色* 键定义颜色相关的观点,提供了视觉一致性的棒棒糖观察,即:不可能(从我的试验和错误检查),设置这样的颜色单独使用AppCompat V7的时候,就像我要怎样做。

观测:我已经用他们的尝试,小时前,在<风格> 父= Widget.AppCompat.Light.ActionBar不工作。它们必须被放置在根<风格> 元素。正是这种错误,让我写这篇文章。

对不起,我的英语技能。

Currently I'm trying to set a custom background color to a Action Bar on AppCompat v7:21. I've tried many possibilities and until now I can't figure out what's going on.

This is my res/values/styles.xml:

<resources>

    <color name="action_bar">#000</color>

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

    </style>

    <!-- ActionBar styles -->
    <style name="MyActionBar" parent="Widget.AppCompat.Light.ActionBar">
        <item name="android:background">@color/action_bar</item>

    </style>

</resources>

解决方案

I've figured out! In fact, lot of UI things changed on API 21, and so on AppCompat v7. You can set Action Bar colors (among others) like this:

<!-- extend one of the Theme.AppCompat themes -->
<style name="Theme.MyTheme" parent="Theme.AppCompat.Light">
    <!-- customize the color palette -->
    <item name="colorPrimary">@color/material_blue_500</item>
    <item name="colorPrimaryDark">@color/material_blue_700</item>
    <item name="colorAccent">@color/material_green_A200</item>
</style>

Where the color* keys defines colors for related views, providing the visual consistency observed on Lollipop, i.e.: Is not possible (checked from my trial and error), set such colors individually when using AppCompat v7, like I was trying to do.

Obs.: I have tried using them, hours ago, on a <style> with parent="Widget.AppCompat.Light.ActionBar" which doesn't work. They must be placed within the "root" <style> element. It was this kind of mistake that make me write this.

Sorry for my English skills.

这篇关于操作栏的颜色不随AppCompat V7的变化:21的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆