变化的Andr​​oid 5.0动作条的颜色 [英] Change Android 5.0 Actionbar color

查看:161
本文介绍了变化的Andr​​oid 5.0动作条的颜色的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在用新的棒棒糖材料设计方针,并想将那个漂亮的抽屉式导航动画在我的应用程序。我已经得到了那么远,使用android.support.v7.app.ActionBarDrawerToggle,但现在我有困难改变的颜色表示,行动起来吧。它保持亮灰色不管我设置的主题。如何将一去改变动作条的颜色?这是我的应用程序的主题是这样的:

  // RES /价值/ styles.xml
<样式名称=AppTheme父=@风格/ Theme.AppCompat.Light.DarkActionBar>

    <项目名称=机器人:actionBarStyle> @风格/动作条< /项目>
    <项目名称=机器人:colorPrimary> @色/ primaryDef< /项目>
    <项目名称=机器人:colorPrimaryDark> @色/ primaryDarkDef< /项目>
    <项目名称=机器人:activatedBackgroundIndicator> @可绘制/ defbg< /项目>
    <项目名称=机器人:colorAccent> @色/ primaryDef< /项目>
    <项目名称=机器人:navigationBarColor> @色/ primaryDarkDef< /项目>

< /风格>

<样式名称=动作条父=机器人:Widget.ActionBar>
    <项目名称=机器人:背景> @色/ primaryDef< /项目>
< /风格>
 

解决方案

AppCompat不使用机器人: prefixed为的材料主题的调色板个项目中的由AppCompat 笔者迁移指南V21。相反,只需要使用它们的名称:

 <样式名称=AppTheme父=@风格/ Theme.AppCompat.Light.DarkActionBar>

    <项目名称=colorPrimary> @色/ primaryDef< /项目>
    <项目名称=colorPrimaryDark> @色/ primaryDarkDef< /项目>
    <项目名称=colorAccent> @色/ primaryDef< /项目>

    <项目名称=机器人:navigationBarColor> @色/ primaryDarkDef< /项目>
    <项目名称=机器人:activatedBackgroundIndicator> @可绘制/ defbg< /项目>
< /风格>
 

在操作栏将被 colorPrimary 是彩色的。

I'm working with the new Lollipop Material Design guidelines and would like to incorporate that nifty navigation drawer animation in my app. I've gotten that far, by using the android.support.v7.app.ActionBarDrawerToggle, but now I'm having difficulty changing the color of said action bar. It stays bright gray no matter what I set the theme to. How would one go about changing the color of the actionbar? This is what my app theme looks like:

//res/values/styles.xml
<style name="AppTheme" parent="@style/Theme.AppCompat.Light.DarkActionBar">

    <item name="android:actionBarStyle">@style/ActionBar</item>
    <item name="android:colorPrimary">@color/primaryDef</item>
    <item name="android:colorPrimaryDark">@color/primaryDarkDef</item>
    <item name="android:activatedBackgroundIndicator">@drawable/defbg</item>
    <item name="android:colorAccent">@color/primaryDef</item>
    <item name="android:navigationBarColor">@color/primaryDarkDef</item>

</style>

<style name="ActionBar" parent="android:Widget.ActionBar">
    <item name="android:background">@color/primaryDef</item>
</style>

解决方案

AppCompat does not use the android: prefixed attributes for the Material Theme color palette items per the migration guide to v21 by the author of AppCompat. Instead, just use the names themselves:

<style name="AppTheme" parent="@style/Theme.AppCompat.Light.DarkActionBar">

    <item name="colorPrimary">@color/primaryDef</item>
    <item name="colorPrimaryDark">@color/primaryDarkDef</item>
    <item name="colorAccent">@color/primaryDef</item>

    <item name="android:navigationBarColor">@color/primaryDarkDef</item>
    <item name="android:activatedBackgroundIndicator">@drawable/defbg</item>
</style>

The Action Bar will be colored by colorPrimary.

这篇关于变化的Andr​​oid 5.0动作条的颜色的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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