问题
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>
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?
This is what I'm currently getting
https://www.dropbox.com/s/alp8d2fhzfd5g71/Screenshot_2015-02-25-21-13-01.png?dl=0
回答1:
UPDATE:
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" />
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>
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>
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 way worked for me!
This should give you the actionbar that looks like the one below a result

回答2:
set @color/carribean in style.xml. This will make your entire screen set with carribean color - including action bar. Then in every activity xml set - android:background="@color/white". This will change background of activity keeping action bar color to carribean.
回答3:
You should create a tool_bar.xml as shown above and copy that code. And since your app targets API 21, you should have two xml files whereby one of them is tool_bar.xml(v21). Whatever code you'll have in the (v21) xml determines what will be displayed on your Lollipop device. Whatever code is in the other xml determines what will be displayed on older devices
回答4:
If you want to change Action bar color of Android App. Just take care of these 3 files
color.xml ( Defining action bar color )
<color name="colorPrimary">#4613AC</color>
<color name="colorPrimaryDark">#4613AC</color>
style.xml ( Defining style of action bar )
<style name="AppTheme" parent="Theme.AppCompat.Light.DarkActionBar">
<!-- Customize your theme here. -->
<item name="colorPrimary">@color/colorPrimary</item>
<item name="colorPrimaryDark">@color/colorPrimaryDark</item>
Manifext.xml ( Applying action bar to App )
<application
android:allowBackup="true"
android:icon="@drawable/logo"
android:label="BarCode Scanner Generator"
android:largeHeap="true"
android:theme="@style/AppTheme" > //This Line apply AppTheme to your app
来源:https://stackoverflow.com/questions/28719993/android-studio-action-bar-color-not-changing