Changing Action Bar attributes with AppCompat android - android

I am trying to get a red action bar with white text and I would also like to customize the font of the text, nothing I have tried works, the answer given here Change Background color of the action bar using AppCompat doesn't work. Here is my xml
<resources xmlns:tools="http://schemas.android.com/tools">
<!-- Base application theme. -->
<style name="AppTheme" parent="Theme.AppCompat">
<!-- Customize your theme here. -->
<item name="android:actionBarStyle">#style/MyActionBar</item>
</style>
<style name="MyActionBar" parent="#android:style/Widget.Holo.Light.ActionBar.Solid.Inverse">
<item name="android:titleTextStyle">#style/ActionBarTitleText</item>
<item name="android:background">#color/red</item>
<item name="background">#color/red</item>
</style>
<style name="ActionBarTitleText">
<item name="android:textColor">#android:color/white</item>
</style>
It seems like everything in here is being ignored, the action bar is black, along with basically everything else on screen, which I really don't want.

make two folders under res (values and values-v14) if they are not there.
add this code in res (values) folder
<?xml version="1.0" encoding="utf-8"?>
<resources>
<style name="Theme.Styled" parent="#style/Theme.AppCompat.Light">
<item name="actionBarStyle">#style/Widget.Styled.ActionBar</item>
</style>
<style name="Widget.Styled.ActionBar"
parent="#style/Widget.AppCompat.Light.ActionBar">
<item name="background">#color/red</item>
<item name="titleTextStyle">#style/MyTextColor</item>
</style>
<style name="MyTextColor"
parent="#style/TextAppearance.AppCompat.Widget.ActionBar.Title">
<item name="android:textColor">#color/white</item>
</style>
then this code in res (values-v14) add this code
<?xml version="1.0" encoding="utf-8"?>
<resources>
<style name="Theme.Styled" parent="#style/Theme.AppCompat.Light">
<item name="android:actionBarStyle">#style/Widget.Styled.ActionBar</item>
</style>
<style name="Widget.Styled.ActionBar"
parent="#style/Widget.AppCompat.Light.ActionBar">
<item name="android:background">#color/red</item>
<item name="android:titleTextStyle">#style/MyTextColor</item>
</style>
<style name="MyTextColor"
parent="#style/TextAppearance.AppCompat.Widget.ActionBar.Title">
<item name="android:textColor">#color/white</item>
</style>
In your manifest set theme to Theme.Styled

Related

Change the title text color in the Android ActionBar via xml

I want to change the title text color of the ActionBar in my app. I have tried in many ways but I can't achieve it. I don't want to do it programatically because when the app is launched it shows the action bar with previous color and then changes to the new one. I'm supporting from Api Level 8 and my xml was generated with the Android Action Bar Style Generator. Then I tried to change the title text color with this . The title text color is still black.
This is my code:
<resources>
<style name="Theme.Dbtools_style" parent="#style/Theme.AppCompat.Light">
<item name="actionBarItemBackground">#drawable/selectable_background_dbtools_style</item>
<item name="popupMenuStyle">#style/PopupMenu.Dbtools_style</item>
<item name="dropDownListViewStyle">#style/DropDownListView.Dbtools_style</item>
<item name="actionBarTabStyle">#style/ActionBarTabStyle.Dbtools_style</item>
<item name="actionDropDownStyle">#style/DropDownNav.Dbtools_style</item>
<item name="actionBarStyle">#style/ActionBar.Solid.Dbtools_style</item>
<item name="actionModeBackground">#drawable/cab_background_top_dbtools_style</item>
<item name="actionModeSplitBackground">#drawable/cab_background_bottom_dbtools_style</item>
<item name="actionModeCloseButtonStyle">#style/ActionButton.CloseMode.Dbtools_style</item>
<!-- Remove icon in Action Bar -->
<item name="android:displayOptions">showHome|homeAsUp|showTitle</item>
<item name="displayOptions">showHome|homeAsUp|showTitle</item>
<item name="android:icon">#android:color/transparent</item>
<!-- Support library compatibility -->
<item name="actionBarStyle">#style/ActionBar.Solid.Dbtools_style</item>
</style>
<style name="ActionBar.Solid.Dbtools_style" parent="#style/Widget.AppCompat.Light.ActionBar.Solid">
<item name="background">#drawable/ab_solid_dbtools_style</item>
<item name="backgroundStacked">#drawable/ab_stacked_solid_dbtools_style</item>
<item name="backgroundSplit">#drawable/ab_bottom_solid_dbtools_style</item>
<item name="progressBarStyle">#style/ProgressBar.Dbtools_style</item>
<!-- Title Text Color -->
<item name="android:titleTextStyle">#style/MyActionBarTitleText</item>
<!-- Support library compatibility -->
<item name="titleTextStyle">#style/MyActionBarTitleText</item>
</style>
<style name="ActionBar.Transparent.Dbtools_style" parent="#style/Widget.AppCompat.Light.ActionBar">
<item name="background">#drawable/ab_transparent_dbtools_style</item>
<item name="progressBarStyle">#style/ProgressBar.Dbtools_style</item>
</style>
<style name="PopupMenu.Dbtools_style" parent="#style/Widget.AppCompat.Light.PopupMenu">
<item name="android:popupBackground">#drawable/menu_dropdown_panel_dbtools_style</item>
</style>
<style name="DropDownListView.Dbtools_style" parent="#style/Widget.AppCompat.Light.ListView.DropDown">
<item name="android:listSelector">#drawable/selectable_background_dbtools_style</item>
</style>
<style name="ActionBarTabStyle.Dbtools_style" parent="#style/Widget.AppCompat.Light.ActionBar.TabView">
<item name="android:background">#drawable/tab_indicator_ab_dbtools_style</item>
</style>
<style name="DropDownNav.Dbtools_style" parent="#style/Widget.AppCompat.Light.Spinner.DropDown.ActionBar">
<item name="android:background">#drawable/spinner_background_ab_dbtools_style</item>
<item name="android:popupBackground">#drawable/menu_dropdown_panel_dbtools_style</item>
<item name="android:dropDownSelector">#drawable/selectable_background_dbtools_style</item>
</style>
<style name="ProgressBar.Dbtools_style" parent="#style/Widget.AppCompat.ProgressBar.Horizontal">
<item name="android:progressDrawable">#drawable/progress_horizontal_dbtools_style</item>
</style>
<style name="ActionButton.CloseMode.Dbtools_style" parent="#style/Widget.AppCompat.Light.ActionButton.CloseMode">
<item name="android:background">#drawable/btn_cab_done_dbtools_style</item>
</style>
<!-- this style is only referenced in a Light.DarkActionBar based theme -->
<style name="Theme.Dbtools_style.Widget" parent="#style/Theme.AppCompat">
<item name="popupMenuStyle">#style/PopupMenu.Dbtools_style</item>
<item name="dropDownListViewStyle">#style/DropDownListView.Dbtools_style</item>
</style>
<!-- ActionBar title text -->
<style name="MyActionBarTitleText" parent="#style/TextAppearance.AppCompat.Widget.ActionBar.Title">
<item name="android:textColor">#color/white</item>
</style>
I solved my problem. The problem was that I was testing in a device with api level 14+ and I just added the style to res/values . I had to add the style in res/values-v14 too. I attach my code:
res/values/styles.xml
<resources xmlns:android="http://schemas.android.com/apk/res/android">
<style name="Theme.Dbtools_style" parent="#style/Theme.AppCompat.Light">
<!-- Title Text Color -->
<item name="actionMenuTextColor">#color/white</item>
</style>
<style name="ActionBar.Solid.Dbtools_style" parent="#style/Widget.AppCompat.Light.ActionBar.Solid">
<!-- Title Text Color -->
<item name="titleTextStyle">#style/MyActionBarTitleText</item>
</style>
<!-- ActionBar title text -->
<style name="MyActionBarTitleText" parent="#style/TextAppearance.AppCompat.Widget.ActionBar.Title">
<item name="android:textColor">#color/white</item>
</style>
res/values-v14/styles.xml
<style name="Theme.Dbtools_style" parent="#style/Theme.AppCompat.Light">
<item name="android:actionBarStyle">#style/ActionBar.Solid.Dbtools_style</item>
<!-- Title Text Color -->
<item name="android:actionMenuTextColor">#color/white</item>
</style>
<style name="ActionBar.Solid.Dbtools_style" parent="#style/Widget.AppCompat.Light.ActionBar.Solid">
<!-- Title Text color -->
<item name="android:titleTextStyle">#style/MyActionBarTitleText</item>
</style>
<!-- ActionBar title text -->
<style name="MyActionBarTitleText" parent="#style/TextAppearance.AppCompat.Widget.ActionBar.Title">
<item name="android:textColor">#color/white</item>
<!-- The textColor property is backward compatible with the Support Library -->
</style>
You Have to do two things:
Styles.xml
<style name="MyTheme" parent="#android:style/Theme.Holo">
<item name="android:actionBarStyle">#style/MyActionBar</item>
</style>
<style name="MyActionBar" parent="#android:style/Widget.Holo.Light.ActionBar">
<item name="android:background">#FF9D21</item>
<item name="android:titleTextStyle">#style/MyActionBarTitleText</item>
</style>
<style name="MyActionBarTitleText"
parent="#android:style/TextAppearance.Holo.Widget.ActionBar.Title">
<item name="android:textColor">#color/red</item>
</style>
Colors.xml
<?xml version="1.0" encoding="utf-8"?>
<resources>
<color name="red">#FF0000</color>
</resources>
This link might help you out with the appropriate color you want.
This link is also helpful.
Set titletextstyle and subtitletextstyle too ...
This is what worked for me. ..
If you want to change that using xml ...
This is what worked for me ...
<style name="MyActionBar"
parent="#style/Widget.AppCompat.Light.ActionBar.Solid.Inverse">
<item name="android:background">#color/titleBarBgColor</item>
<item name="android:titleTextStyle">#style/EldTheme.ActionBar.TitleTextStyle</item>
<item name="android:subtitleTextStyle">#style/EldTheme.ActionBar.TitleTextStyle</item>
<!-- Support library compatibility -->
<item name="background">#color/titleBarBgColor</item>
<item name="titleTextStyle">#style/EldTheme.ActionBar.TitleTextStyle</item>
<item name="subtitleTextStyle">#style/EldTheme.ActionBar.TitleTextStyle</item>
</style>
<style name="EldTheme.ActionBar.TitleTextStyle" parent="#style/TextAppearance.AppCompat.Widget.ActionBar.Title">
<item name="android:textColor">#color/titleBarTextColor</item>
</style>
for me this one worked.
go to /value/colors.xml
add <color name="black">#000000</color> //if you want black to your <resources>
to to /values/styles.xml
add <item name="titleTextColor">#color/black</item> to your <style>
here is some example code, too:
color.xml:
<resources>
<color name="colorPrimary">#ffffff</color>
<color name="colorPrimaryDark">#000000</color>
<color name="colorAccent">#03DAC5</color>
<color name="black">#000000</color>
</resources>
styles.xml:
<style name="AppTheme" parent="Theme.AppCompat.Light.DarkActionBar">
<!-- Customize your theme here. -->
<item name="colorPrimary">#color/colorPrimary</item>
<item name="colorPrimaryDark">#color/colorPrimaryDark</item>
<item name="colorAccent">#color/colorAccent</item>
<item name="titleTextColor">#color/black</item>
</style>```

Change ActionBar OverflowMenu Background color

Ive added a lot of properties to change to background color of the overflow menu, none seem to work.
Here are a few links i've refered (other than SO questions):
http://blog.stylingandroid.com/archives/1267
http://android-developers.blogspot.in/2011/04/customizing-action-bar.html
res>values>
style.xml
<resources xmlns:android="http://schemas.android.com/apk/res/android">
<style name="AppBaseTheme" parent="android:Theme.Light"></style>
<!-- Application theme. -->
<style name="AppTheme" parent="AppBaseTheme">
<item name="android:actionBarStyle">#style/MyActionBar</item>
<item name="android:dropDownListViewStyle">#style/MyDropDownListView</item>
<item name="android:actionDropDownStyle">#style/MyDropDownNav</item>
<item name="android:popupMenuStyle">#style/MyPopupMenu</item>
</style>
<style name="MyPopupMenu" parent="#android:style/Widget.Holo.ListPopupWindow">
<item name="android:popupBackground">#drawable/menu_dropdown_panel</item>
</style>
<style name="MyActionBar" parent="#android:style/Widget.Holo.Light.ActionBar">
<item name="android:background">#28bda9</item>
<item name="android:titleTextStyle">#style/Theme.MyAppTheme.ActionBar.TitleTextStyle</item>
</style>
<style name="Theme.MyAppTheme.ActionBar.TitleTextStyle" parent="android:style/TextAppearance.Holo.Widget.ActionBar.Title">
<item name="android:textColor">#28bda9</item>
</style>
<!-- style the items within the overflow menu -->
<style name="MyDropDownListView" parent="android:style/Widget.Holo.ListView.DropDown">
<item name="android:listSelector">#28bda9</item>
</style>
<!-- style the list navigation -->
<style name="MyDropDownNav" parent="android:style/Widget.Holo.Light.Spinner">
<item name="android:background">#28bda9</item>
<item name="android:popupBackground">#28bda9</item>
<item name="android:dropDownSelector">#28bda9</item>
</style>
</resources>
Edit: I have changed the code to match the solution. This was the error:
<style name="MyPopupMenu" parent="#android:style/Widget.Holo.ListPopupWindow">
<item name="android:popupBackground">**#28bda9**</item>
</style>
You're on the right track, but the popupBackground is not merely a color.
You have to change the drawable.
Below is the default drawable for Holo Light (usually called menu_dropdown_panel).
Change the color using your favorite image editor, and put it your drawable-x folder.
The needed style will be as follows:
<style name="AppTheme" parent="AppBaseTheme">
...
<item name="android:popupMenuStyle">#style/MyPopupMenu</item>
</style>
<style name="MyPopupMenu" parent="#android:style/Widget.Holo.ListPopupWindow">
<item name="android:popupBackground">#drawable/menu_dropdown_panel</item>
</style>

Overflow Menu Items Text

I went through enough samples and tried many combinations for entire two days, i have missed to grasp something. please correct me...
I Want to change the Color of Menu items Text present in overflow menu.
Thank you
my style file
<resources xmlns:android="http://schemas.android.com/apk/res/android">
<!-- Application theme. -->
<style name="AppTheme" parent="#android:style/Theme.Holo.Light">
<item name="android:actionBarStyle">#style/ActionBarTheme</item>
<item name="android:popupMenuStyle">#style/PopupMenuTheme</item>
<item name="android:actionMenuTextColor">#android:color/white</item>
<item name="android:actionOverflowButtonStyle">#style/MenuButtonTheme</item>
</style>
<!-- action bar -->
<style name="ActionBarTheme" parent="#android:Widget.Holo.Light.ActionBar">
<item name="android:background">#color/SmugeBlue</item>
<item name="android:titleTextStyle">#style/ActionBarTitle</item>
</style>
<!-- action bar title -->
<style name="ActionBarTitle" parent="#android:style/TextAppearance.Holo.Widget.ActionBar.Title.Inverse">
<item name="android:textColor">#android:color/white</item>
</style>
<!-- pop up menu background color -->
<style name="PopupMenuTheme" parent="#android:style/Widget.Holo.Light.ListPopupWindow">
<item name="android:popupBackground">#color/SmugeBlue</item>
<item name="android:textStyle">#style/MenuText</item>
</style>
<style name="MenuText">
<item name="android:textColor">#android:color/white</item>
</style>
<style name="MenuButtonTheme" parent="#android:style/Widget.Holo.ActionButton.Overflow">
<item name="android:src">#drawable/overflow_menu_button</item>
</style>
</resources>
---- updating with solution i found handy for my case
<style name="overflow_menu_text_color">
<item name="android:textColor">#android:color/white</item>
</style>
<style name="AppTheme" parent="#android:style/Theme.Holo.Light">
....
<item name="android:itemTextAppearance">#style/overflow_menu_text_color</item>
.....
</style>

Styling Action Bar Text Color - Android

<style name="Theme.RateItTheme" parent="#android:style/Theme.Holo.Light">
<item name="android:actionBarStyle">#style/MyActionBar</item>
<item name="android:titleTextStyle">#style/MyActionBar.Text</item>
</style>
<style name="MyActionBar" parent="#android:style/Widget.Holo.Light.ActionBar">
<item name="android:background">#2E495E</item>
</style>
<style name="MyActionBar.Text" parent="#android:style/TextAppearance.Holo.Widget.ActionBar.Title">
<item name="android:textColor">#ECECEC</item>
</style>
I have been able to change the background, but not the text color. Or the overflow menu "three dots". My code is above.
You need to move your titleTextStyle attribute into your MyActionBar style. Do you understand why it's supposed to be placed there rather than where you had it originally?
<style name="MyActionBar" parent="#android:style/Widget.Holo.Light.ActionBar">
<item name="android:background">#2E495E</item>
<item name="android:titleTextStyle">#style/MyActionBar.Text</item>
</style>
As far as changing the Overflow icon, I think that's what mean when you say "three dots", I've already written a post about that here.
Try this
<?xml version="1.0" encoding="utf-8"?>
<!-- For honeycomb and up -->
<resources>
<style name="Theme.RateItTheme" parent="#android:style/Theme.Holo.Light">
<item name="android:actionBarStyle">#style/MyActionBar</item>
<item name="android:actionMenuTextColor">#color/actionBarText</item>
</style>
<style name="MyActionBar" parent="#android:style/Widget.Holo.Light.ActionBar">
<item name="android:background">#2E495E</item>
<item name="android:titleTextStyle">#style/MyActionBar.Text</item>
</style>
<style name="MyActionBar.Text" parent="#android:style/TextAppearance">
<item name="android:textColor">#ECECEC</item>
</style>
</resources>

Modify style of Android items in the ActionBar

How can I modify the style of the items on the Action bar of an Android Application?
I tryed the following:
<item name="android:actionBarStyle">#style/ActionBar.Light</item>
<style name="ActionBar.Light" parent="#style/ActionBar">
<item name="android:background">#color/black</item>
<item name="android:actionMenuTextColor">#FF00FF</item>
</style>
The background of the Action bar I was able to modify, but not the text Colors of the items in the Action bar. How can I do it?
EDIT:
I tried pretty much all the android:action attributes I found, but I couldn't manage to change anything other than the background. Only the first <item name="android:background">#FF0000</item> of the following code makes changes on my code. No matter which values I put on the Test style, it doesn't change anything. Why is it happening?
<item name="android:actionBarStyle">#style/ActionBar.Light</item>
<style name="ActionBar.Light" parent="#style/ActionBar">
<item name="android:background">#FF0000</item>
<item name="android:actionMenuTextColor">#style/Test</item>
<item name="android:actionButtonStyle">#style/Test</item>
<item name="android:actionModeBackground">#style/Test</item>
<item name="android:actionMenuTextAppearance">#style/Test</item>
</style>
<style name="Test">
<item name="android:textColor">#color/white</item>
<item name="android:background">#FF0000</item>
</style>
If you want to change the color of the menu items in the action bar you have to set the actionMenuTextColor in your theme style.
<style name="PortfolioTheme" parent="android:style/Theme.Holo.Light">
<item name="android:actionMenuTextColor">#24598a</item>
<item name="actionMenuTextColor">#24598a</item>
</style>
You don't define the menu item colors in the actionMenuTextAppearance!
You can change the color by:-
<?xml version="1.0" encoding="utf-8"?>
<resources>
<style name="MyTheme" parent="#android:style/Theme.Holo.Light">
<item name="android:actionBarStyle">#style/MyTheme.ActionBarStyle</item>
</style>
<style name="MyTheme.ActionBarStyle" parent="android:style/Widget.Holo.ActionBar">
<item name="android:titleTextStyle">#style/MyTheme.ActionBar.TitleTextStyle</item>
</style>
<style name="MyTheme.ActionBar.TitleTextStyle" parent="android:style/TextAppearance.Holo.Widget.ActionBar.Title">
<item name="android:textColor">#color/red</item>
</style>
</resources>

Categories

Resources