简体   繁体   中英

How to change text color and background color of action bar items in android

I want to change text color and background color of action bar item which is white here. I searched alot but am not able to change this color.

Please check my code which I am using to customise action bar.

final ActionBar actionBar = getActionBar(); 
ColorDrawable colorDrawable = new ColorDrawable(Color.parseColor (Hexa color)); 
actionBar . setBackgroundDrawable (colorDrawable);

这是我要进行更改的屏幕。

In your "res/values/themes.xml" file, do something like this:

<style name="CustomActionBarTheme"
   parent="@android:style/Theme.Holo">
<item name="android:popupMenuStyle">@style/MyPopupMenu</item>
<item name="android:itemTextAppearance">@style/TextAppearance</item>
</style>
<!-- Popup Menu Background Color styles -->
<style name="MyPopupMenu" 
   parent="@android:style/Widget.Holo.ListPopupWindow">
<item name="android:popupBackground">@color/Your_color_for_background</item> 
</style>
<!-- Popup Menu Text Color styles -->
   <style name="TextAppearance">
      <item name="android:textColor">@color/Your_color_for_text</item>
</style>

And then in your manifest

<application
   android:theme="@style/CustomActionBarTheme" 
... >

Check this question and some of its answers for more clarification.

You can customize the action bar like below..

<!-- Base application theme. -->
<style name="Theme.AppTheme" parent="android:Theme.Holo.Light.DarkActionBar">
    <item name="android:actionBarStyle">@style/Theme.AppTheme.actionBar</item>
    <item name="android:actionBarWidgetTheme">@style/Theme.AppTheme.actionBar.widget</item>
    <item name="android:textViewStyle">@style/Theme.AppTheme.textView</item>
</style>

<!-- Actionbar things -->

<style name="Theme.AppTheme.actionBar" parent="android:Widget.Holo.Light.ActionBar.Solid">
    <item name="android:titleTextStyle">@style/Theme.AppTheme.actionBarTitle</item>
    <item name="android:subtitleTextStyle">@style/Theme.AppTheme.actionBarSubtitle</item>
    <item name="android:background">@android:color/holo_blue_dark</item>
    <item name="android:icon">@drawable/ic_launcher</item>
</style>

<style name="Theme.AppTheme.actionBarTitle" parent="android:TextAppearance.Holo.Widget.ActionBar.Title">
    <item name="android:textColor">@android:color/white</item>
</style>

<style name="Theme.AppTheme.actionBarSubtitle" parent="android:TextAppearance.Holo.Widget.ActionBar.Subtitle">
    <item name="android:textColor">@android:color/white</item>
</style>

<style name="Theme.AppTheme.actionBar.widget" parent="@android:style/Theme.Holo">
    <item name="android:popupMenuStyle">@style/Theme.AppTheme.actionBar.PopupMenu</item>
    <item name="android:dropDownListViewStyle">@style/Theme.AppTheme.actionBar.DropDownListView</item>
</style>

<style name="Theme.AppTheme.actionBar.PopupMenu" parent="@android:style/Widget.Holo.ListPopupWindow">
    <item name="android:popupBackground">@android:color/holo_purple</item>
</style>

<style name="Theme.AppTheme.actionBar.DropDownListView" parent="@android:style/Widget.Holo.ListView.DropDown">
    <item name="android:listSelector">@android:color/holo_red_light</item>
</style>

<!-- Standard Widgets -->

<style name="Theme.AppTheme.textView" parent="android:Widget.TextView"></style>

Hope this will help you!

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM