Android Studio 操作栏颜色未更改

标签 android xml android-studio android-5.0-lollipop

在运行 Android 5.0 lollipop 的 styles.xml 中

<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?

这是我目前得到的

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

最佳答案

更新:

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

<?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 文件中:

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

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

</resources>

这是 styles.xml 文件的代码:

<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 文件中:

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

这种方式对我有用!

这应该为您提供看起来像结果下方的操作栏

enter image description here

关于Android Studio 操作栏颜色未更改,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/28719993/

相关文章:

java - TabHost 中的 ListView

android - 用于 INNER JOIN 的 sqliteDatabase.query()

android - 为什么我来自 url 的图像没有出现在 TouchableOpacity 中

java - 即使解析了 XML,Document.toString() 也是 "[#document: null]"

Java:在另一个类中访问 XML 值作为新变量

java - findViewById(R.id.screen) 返回 null

android-studio - qemu-system-x86_64.exe' : Invalid argument 3:06 PM Emulator: Process finished with exit code 22

android - 在 Android Studio 和 Gradle 中使用 ViewPagerIndicator 库

android - Firebase Android 云函数更改超时

android - 良好的 Android UI 设计模式引用