Android Studio 操作栏颜色不变 [英] Android Studio Action Bar Color not Changing

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

问题描述

在运行 Android 5.0 棒棒糖的 style.xml 中

in styles.xml running Android 5.0 lollipop

<resources>
<!-- Base application theme. -->
<style name="AppTheme" parent="Theme.AppCompat.Light.DarkActionBar">
    <!-- Customize your theme here. -->
    <item name="android:colorPrimary">@color/primary</item>
    <item name="android:colorPrimaryDark">@color/primary_dark</item>
    <item name="android:colorAccent">@color/accent</item>
    <item name="android:statusBarColor">@color/primary</item>
    <item name="android:colorAccent">@color/accent</item>
    <item name="android:textColorPrimary">@color/primary_text</item>
    <item name="android:textColor">@color/secondary_text</item>
    <item name="android:navigationBarColor">@color/primary_dark</item>
</style>

当我构建并运行它时,我只将状态栏设置为 colorPrimaryDark,而工具栏保持黑色.我如何让它变成 colorPrimary?

when I build it and run it, I only get the status bar colored with the colorPrimaryDark while the toolbar remains black. How do I make it turn to colorPrimary?

这是我目前得到的

https://www.dropbox.com/s/alp8d2fhzfd5g71/Screenshot_2015-02-25-21-13-01.png?dl=0

推荐答案

更新:

在您的布局文件夹中创建一个名为 tool_bar.xml 的新文件并粘贴以下代码:

Make a new file in your layouts folder called tool_bar.xml and paste the following code:

<?xml version="1.0" encoding="utf-8"?>
<android.support.v7.widget.Toolbar
    android:layout_height="wrap_content"
    android:layout_width="match_parent"
    android:background="@color/ColorPrimary"
    android:elevation="2dp"
    android:theme="@style/Base.ThemeOverlay.AppCompat.Dark"
    xmlns:android="http://schemas.android.com/apk/res/android" />

在您的 color.xml 文件中添加这些颜色:

Add these colors in your color.xml file:

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

    <color name="ColorPrimary">#00897B</color>
    <color name="ColorPrimaryDark">#00695C</color>

</resources>

这是你的styles.xml 文件的代码:

This is the code for your styles.xml file:

<resources>

   <!-- Base application theme. -->
   <style name="AppTheme" parent="Theme.AppCompat.Light.NoActionBar">
       <item name="colorPrimary">@color/ColorPrimary</item>
       <item name="colorPrimaryDark">@color/ColorPrimaryDark</item>
   </style>

您应该将以下代码添加到 MainActivity.xml 文件中:

You should add the folowing code to your MainActivity.xml file:

<include
    android:id="@+id/tool_bar"
    layout="@layout/tool_bar"
    android:layout_height="wrap_content"
    android:layout_width="match_parent" />

这种方式对我有用!

这应该会给你一个看起来像结果下面的操作栏

This should give you the actionbar that looks like the one below a result

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

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