问题
I want to change the color of the title bar. I tried this:
<style name="AppTheme" parent="AppBaseTheme">
<!-- All customizations that are NOT specific to a particular API-level can go here. -->
<item name="android:actionBarStyle">@style/ColorBar</item>
</style>
<style name="ColorBar" parent="@android:style/Widget.Holo.Light.ActionBar">
<item name="android:background">@color/white</item>
<item name="android:textColor">@color/orange</item>
</style>
But it doesn't work. What is wrong in my code shown above?
EDIT : it's the color of the text i want to change, not the background (it's running for the background)
回答1:
This should work for all devices, you will need the support library (appcompat_v7)
<style name="Theme" parent="@style/BaseTheme"></style>
<style name="BaseTheme" parent="Theme.AppCompat.Light.DarkActionBar">
<item name="actionBarStyle">@style/ActionBar</item>
<item name="android:actionBarStyle">@style/ActionBar</item>
</style>
<style name="ActionBar" parent="@style/Widget.AppCompat.Light.ActionBar">
<item name="android:background">@color/orange </item>
<item name="background">@color/orange </item>
<item name="android:titleTextStyle">@style/ActionBar.Text</item>
<item name="titleTextStyle">@style/ActionBar.Text</item>
</style>
<style name="ActionBar.Text" parent="@android:style/TextAppearance.Medium">
<item name="android:textColor">@color/orange</item>
</style>
manifest :
android:theme="@style/Theme"
回答2:
There may be problem with the android version. You should consider old ones and new ones. Try adding these both lines for different versions.
<item name="android:background">@drawable/your_color</item>
<item name="background">@drawable/your_color</item>
回答3:
Does changing the parent to parent="@android:style/Widget.Holo.Light.ActionBar.Solid"
make a difference?
If not, let me know what happens if you move the
<item name="android:actionBarStyle">@style/ColorBar</item>
into the AppBaseTheme
style
Try setting all of these:
<item name="android:background">@color/something</item>
<item name="android:backgroundStacked">@color/something</item>
<item name="android:backgroundSplit">@color/something</item>
回答4:
This is an easy way for settings the color of the actionbar-title by Java
getActionBar().setTitle(Html.fromHtml("<font color=\"#ffffff\">" + "TITLE" + "</font>"));
If you're using a support library, then you can use getSupportActionBar();
.
回答5:
I'm new to all of this but I found it easier to go to Res > Value > colors.xml and from there you can change the "primary color." This changed the title bar to the color I selected.
来源:https://stackoverflow.com/questions/23801252/change-color-title-bar