change ActionBar Spinner text color - android

I already read many ways to change spinner textColor in an ActionBar, but I really can't figure it out what is missing to make what I need.
This is how I have my actionbar spinner:
As you can see, I have white text on spinner items. I need to change it to black.
My res/styles file is this one.
<resources xmlns:android="http://schemas.android.com/apk/res/android">
<style name="AppBaseTheme" parent="#style/Theme.AppCompat.Light.DarkActionBar">
<!-- API 14 theme customizations can go here. -->
<item name="android:dropDownListViewStyle">#style/MyDropDownListView</item>
<item name="android:dropDownItemStyle">#style/MyDropDownItemView</item>
<!-- <item name="android:textColor">#color/white</item> -->
</style>
<!-- ActionBar styles -->
<style name="MyDropDownListView" parent="#style/Widget.AppCompat.ListView.DropDown">
<item name="android:background">#color/white</item>
</style>
</resources>
I changed background to white, but now i need to change text to black and I can't do it.
Some one can help me?

I think the easiest way is to create a custom spinner item layout for your spinner, but with only a textview & it's color set to whatever you want it to be.
<TextView xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:gravity="center"
android:textSize="14sp"
android:textColor="#000000" />
Here is also a post that explains how to do it by changing the xml styles: Android Actionbar navigation spinner text color
UPDATE:
Remove the "android:" part from the xml statments that change something from the appcompat library. In my app it did the trick. So instead of this:
<style name="AppBaseTheme" parent="#style/Theme.AppCompat.Light.DarkActionBar">
<!-- API 14 theme customizations can go here. -->
<item name="android:dropDownListViewStyle">#style/MyDropDownListView</item>
<item name="android:dropDownItemStyle">#style/MyDropDownItemView</item>
<!-- <item name="android:textColor">#color/white</item> -->
</style>
You remove the "android:" part:
<style name="AppBaseTheme" parent="#style/Theme.AppCompat.Light.DarkActionBar">
<!-- API 14 theme customizations can go here. -->
<item name="dropDownListViewStyle">#style/MyDropDownListView</item>
<item name="dropDownItemStyle">#style/MyDropDownItemView</item>
<!-- <item name="textColor">#color/white</item> -->
</style>
UPDATE 2:
So i'll just post how i style my appcompat apps, so maybe you can see what i don't see. I have 2 folders: resources/values & resources/values-v14.
In the resource/value my style.xml file looks like this:
<style name="Theme.Jamesstyle" parent="#style/Theme.AppCompat.Light">
<item name="actionBarStyle">#style/Actionbar.FlatUi</item>
<item name="actionBarTabStyle">#style/ActionBar.FlatUi.Tabs</item>
<item name="actionBarTabTextStyle">#style/ActionBar.FlatUi.Text</item>
<item name="homeAsUpIndicator">#android:color/transparent</item>
</style>
<style name="Actionbar.FlatUi" parent="#style/Widget.AppCompat.Light.ActionBar.Solid.Inverse">
<item name="background">#color/bizzumi_light</item>
<item name="backgroundStacked">#color/bizzumi_red</item>
<item name="backgroundSplit">#color/bizzumi_red</item>
<item name="titleTextStyle">#style/TitleColor</item>
<item name="displayOptions">showHome|homeAsUp|showTitle</item>
</style>
<style name="TitleColor" parent="#style/TextAppearance.AppCompat.Widget.ActionBar.Title">
<item name="textColor">#000099</item>
</style>
And in my resources/values-v14 style.xml file i have:
<style name="Theme.Jamesstyle" parent="#style/Theme.AppCompat.Light">
<item name="android:actionBarStyle">#style/Actionbar.FlatUi</item>
<item name="android:actionBarTabStyle">#style/ActionBar.FlatUi.Tabs</item>
<item name="android:homeAsUpIndicator">#android:color/transparent</item>
<item name="android:actionBarTabTextStyle">#style/ActionBar.FlatUi.Text</item>
</style>
<style name="Actionbar.FlatUi" parent="#style/Widget.AppCompat.Light.ActionBar.Solid.Inverse">
<item name="android:background">#color/bizzumi_light</item>
<item name="android:backgroundStacked">#color/bizzumi_light</item>
<item name="android:backgroundSplit">#color/bizzumi_light</item>
<item name="android:titleTextStyle">#style/TitleColor</item>i
<item name="android:displayOptions">showHome|homeAsUp|showTitle</item><item name="displayOptions">showHome|homeAsUp|showTitle</item></style>
<style name="TitleColor" parent="#style/TextAppearance.AppCompat.Widget.ActionBar.Title">
<item name="android:textColor">#000099</item>
</style>
Maybe try this folder structure and create 2 different styles.xml files. Otherwise i'm clueless. Good luck!

`<resources xmlns:android="http://schemas.android.com/apk/res/android">
<style name="AppBaseTheme" parent="#style/Theme.AppCompat.Light.DarkActionBar">
<!-- API 14 theme customizations can go here. -->
<item name="android:dropDownListViewStyle">#style/MyDropDownListView</item>
<item name="android:dropDownItemStyle">#style/MyDropDownItemView</item>
<!-- <item name="android:textColor">#color/white</item> -->
</style>
<!-- ActionBar styles -->
<style name="MyDropDownListView" parent="#style/Widget.AppCompat.ListView.DropDown">
<item name="android:background">#color/white</item>
<item name="android:textColor">#000000</item>
</style>

Related

How to change ActionBar Colour

I am trying to change my App ActionBar colour to no success. I am using the this library https://github.com/neokree/MaterialNavigationDrawer;
Here is the style.xml
<?xml version="1.0" encoding="utf-8"?>
<resources>
<!-- Base application theme. -->
<style name="AppTheme" parent="#style/Theme.AppCompat.Light.DarkActionBar">
<!-- Customize your theme here. -->
<item name="android:actionBarStyle">#style/AppTheme.ActionBar</item>
<!-- Support library compatibility -->
<item name="actionBarStyle">#style/AppTheme.ActionBar</item>
<item name="colorControlActivated">#color/color_c</item>
<item name="toolbarStyle">#style/Widget.Toolbar</item>
</style>
<style name="Widget.Toolbar" parent="#style/Widget.AppCompat.Toolbar">
<item name="contentInsetStart">5dp</item>
</style>
<style name="AppTheme.ActionBar" parent="#style/Widget.AppCompat.Light.ActionBar.Solid.Inverse">
<item name="android:background">#color/color_a</item>
<item name="background">#color/color_a</item>
<!-- Support library compatibility -->
</style>
<style name="FullscreenTheme" parent="android:Theme.NoTitleBar">
<item name="android:windowContentOverlay">#null</item>
<item name="android:windowBackground">#null</item>
</style>
<style name="MyNavigationDrawerTheme" parent="MaterialNavigationDrawerTheme.Light.DarkActionBar">
<item name="colorPrimary">#color/color_a</item>
<item name="colorPrimaryDark">#color/color_a</item>
<item name="colorAccent">#FFFFFF</item>
<item name="rippleBackport">true</item>
<item name="singleAccount">true</item>
<item name="multipaneSupport">true</item>
<!--<item name="learningPattern">false</item>-->
</style>
<style name="MySubheaderTheme">
<item name="subheaderTitleColor">#000000</item>
</style>
<style name="MySectionTheme" >
<item name="sectionColorIcon">#000000</item>
<item name="sectionColorText">#000000</item>
<item name="sectionColorNotification">#000000</item>
<item name="sectionBackgroundColorPressed">#160000FF</item>
<item name="sectionBackgroundColorSelected">#0A0000FF</item>
<item name="sectionBackgroundColor">#000000FF</item>
</style>
</resources>
I use the MyNavigationDrawerTheme theme for my activities.
You should be able to set the action bar color using the android:colorPrimary attribute:
<resources>
<!-- inherit from the material theme -->
<style name="AppTheme" parent="android:Theme.Material">
<!-- Main theme colors -->
<!-- your app branding color for the app bar -->
<item name="android:colorPrimary">#color/primary</item>
<!-- darker variant for the status bar and contextual app bars -->
<item name="android:colorPrimaryDark">#color/primary_dark</item>
<!-- theme UI controls like checkboxes and text fields -->
<item name="android:colorAccent">#color/accent</item>
</style>
</resources>
Based on information here
You should create your styles also for v21 and above with a small change (because they natively support material theme).
And in values-v21/style.xml add android:colorPrimary and others attributes with android: prefix to your style:
<style name="MyNavigationDrawerTheme" parent="MaterialNavigationDrawerTheme.Light.DarkActionBar">
<item name="android:colorPrimary">#color/color_a</item>
<item name="android:colorPrimaryDark">#color/color_a</item>
<item name="android:colorAccent">#FFFFFF</item>
<!--...-->
</style>

Android style inheritance

I have two themes, one has ActionBar and one without. It seems redundant to do duplicate the styles, is there any way to simplify it?
Thanks
<style name="AppTheme.NoActionBar" parent="Theme.AppCompat.Light.NoActionBar">
<item name="colorPrimary">#color/primary_color</item>
<item name="android:windowBackground">#color/bg_color</item>
<item name="colorAccent">#color/accent_color</item>
<item name="colorPrimaryDark">#color/darker_color</item>
<!-- Button style -->
<item name="android:buttonStyle">#style/ButtonStyle</item>
<item name="buttonStyle">#style/ButtonStyle</item>
</style>
<!-- Base application theme. -->
<style name="AppTheme" parent="Theme.AppCompat.Light.DarkActionBar">
<item name="colorPrimary">#color/primary_color</item>
<item name="android:windowBackground">#color/bg_color</item>
<item name="colorAccent">#color/accent_color</item>
<item name="colorPrimaryDark">#color/darker_color</item>
<!-- Button style -->
<item name="android:buttonStyle">#style/ButtonStyle</item>
<item name="buttonStyle">#style/ButtonStyle</item>
</style>
<style name="ButtonStyle" parent="Widget.AppCompat.Button">
<item name="android:background">#color/primary_color</item>
</style>
Unfortunately, due to the way that Style/Theme inheritance works, there is no way around this. You could read more about that here:
Android Styles heritage
One option, however, would be to copy the contents of the NoActionBar theme. It turns out that it only contains 2 lines:
<item name="windowActionBar">false</item>
<item name="windowNoTitle">true</item>
So your code would look like this
<!-- Base application theme. -->
<style name="AppTheme" parent="Theme.AppCompat.Light.DarkActionBar">
<item name="colorPrimary">#color/primary_color</item>
<item name="android:windowBackground">#color/bg_color</item>
<item name="colorAccent">#color/accent_color</item>
<item name="colorPrimaryDark">#color/darker_color</item>
<!-- Button style -->
<item name="android:buttonStyle">#style/ButtonStyle</item>
<item name="buttonStyle">#style/ButtonStyle</item>
</style>
<!-- NoActionBar theme -->
<style name="AppTheme.NoActionBar">
<item name="windowActionBar">false</item>
<item name="windowNoTitle">true</item>
</style>
Now you are inheriting the AppTheme attributes as well as getting the NoActionBar behavior. Obviously this is not foolproof if the attributes of NoActionBar change in the future, but it might be a good option for someone with many attributes in their base AppTheme.

Android actionbar background same color as text

This is my first project working with Android (Xamarin) and i was trying to style the ActionBar. I succesfully changed the background color, but now the text within it is either gone or the same color as the background. I think the second because i only changed the background. Below is my Styles.xml.
<?xml version="1.0" encoding="UTF-8" ?>
<resources>
<style name="hme" parent="android:Theme.Material">
<item name="android:actionBarStyle">#style/hme.ActionBar</item>
<!-- Support library compatibility -->
<item name="actionBarStyle">#style/hme.ActionBar</item>
</style>
<!-- ActionBar styles -->
<style name="hme.ActionBar" parent="#style/Widget.AppCompat.ActionBar.Solid">
<item name="android:background">#color/primary</item>
<item name="android:titleTextStyle">#style/hme.ActionBar.Text</item>
<!-- Support library compatibility -->
<item name="background">#color/primary</item>
</style>
<style name="hme.ActionBar.Text" parent="#style/TextAppearance.AppCompat.Widget.ActionBar.Title">
<item name="android:textColor">#color/white</item>
</style>
<style name="hme.Splash" parent="android:Theme">
<item name="android:windowBackground">#drawable/splash</item>
<item name="android:windowNoTitle">true</item>
</style>
</resources>
And here is a screenshot on Gyazo of how it looks. (Not enough rep to post a picture): http://gyazo.com/161cd58ced1f7a147b29f8ee6aa401af
I checked other fixes on SO on diffent questions but nothing seems to work, can anybody help me?
You can add
<item name="android:textColorPrimary">#android:color/black</item>
into your hme style:
<style name="hme" parent="android:Theme.Material">
<item name="android:actionBarStyle">#style/hme.ActionBar</item>
<item name="android:textColorPrimary">#android:color/black</item>
<!-- Support library compatibility -->
<item name="actionBarStyle">#style/hme.ActionBar</item>
</style>
Check also:
<item name="android:textColor">#android:color/black</item>
<item name="android:textColorSecondary">#android:color/black</item>
may be useful.

Change Color of Actionbar in Android

I am trying to change the background color of actionbar in my App but this is showing different on my app. Instead of coloring the actionbar the whole activity is color.
I am not sure why this is happening? I just want the main actionbar and settings actionbar colored.
Please check the screenshot.
Main Activity Map:
Preference Settings:
I also have transparent Actionbar with UP Navigation enabled for all my sub activities other than the main activity and preference settings activity.
I am not sure why it is showing like the above:
Here is style.xml (values-v14):
<resources xmlns:android="http://schemas.android.com/apk/res/android">
<style name="AppBaseTheme" parent="android:Theme.Holo.Light.DarkActionBar">
<item name="android:background">#FF5050</item>
</style>
<style name="dialogtheme" parent="#android:style/Theme.Holo.Light.DarkActionBar"></style>
<!-- Transparent ActionBar Style -->
<style name="AppTheme.Light.ActionBar.Transparent" parent="#android:style/Widget.Holo.Light.ActionBar.Solid.Inverse">
<item name="android:background">#android:color/transparent</item>
</style>
<!-- Activity Theme with transparent ActionBar -->
<style name="AppTheme.TransparentActionBar.Light" parent="#style/AppBaseTheme">
<item name="android:actionBarStyle">#style/AppTheme.Light.ActionBar.Transparent</item>
<item name="android:windowIsTranslucent">true</item>
<item name="android:backgroundDimEnabled">true</item>
<item name="android:windowActionBarOverlay">true</item>
<item name="android:windowContentOverlay">#null</item>
<item name="android:displayOptions">showHome|homeAsUp|showTitle</item>
<item name="android:icon">#android:color/transparent</item>
<item name="android:actionBarTabTextStyle">#style/ActionBarTabTextStyle.Tabtheme</item>
<item name="android:actionBarDivider">#drawable/verticallinefordivder</item>
<item name="android:actionBarTabStyle">#style/ActionBarTabStyle.MapsLocation</item>
</style>
<style name="simpledialog" parent="android:Theme.Holo.Light.Dialog">
<item name="android:windowNoTitle">true</item>
</style>
<style name="ActionBarTabTextStyle.Tabtheme" parent="#style/AppBaseTheme">
<item name="android:textSize">18sp</item>
<item name="android:textStyle">bold</item>
<item name="android:textColor">#android:color/black</item>
</style>
<style name="ActionBarTabStyle.MapsLocations" parent="#android:style/Widget.Holo.Light.ActionBar.TabView">
<item name="android:background">#drawable/tab_indicator</item>
</style>
<style name="myPreferenceTheme" parent="#style/AppBaseTheme">
<item name="android:textColor">#color/blue</item>
</style>
<style name="Widget.ActionButton" parent="#style/AppBaseTheme">
<item name="android:background">?android:attr/actionBarItemBackground</item>
<item name="android:paddingLeft">12dip</item>
<item name="android:paddingRight">12dip</item>
<item name="android:minWidth">56dip</item>
<item name="android:minHeight">?android:attr/actionBarSize</item>
</style>
</resources>
A little change and you action bar will be red:
<style name="AppBaseTheme" parent="android:Theme.Holo.Light.DarkActionBar">
<item name="android:actionBarStyle">#style/AppTheme.Light.ActionBar</item>
</style>
<style name="dialogtheme" parent="#android:style/Theme.Holo.Light.DarkActionBar"></style>
<!-- Transparent ActionBar Style -->
<style name="AppTheme.Light.ActionBar" parent="#android:style/Widget.Holo.ActionBar">
<item name="android:background">#FF5050</item>
</style>
I have changed item in AppBaseTheme & AppTheme.Light.ActionBar .
Now you are good to go. let me know if it works however working at my end :P
You can try set custom view in action bar.
actionBar.setDisplayShowCustomEnabled(true);
actionBar.setCustomView(you_custom_layout);
I know this is not right answer to this question but if you want to edit your ActionBar, you can use this online Android Action Bar Style Generator.
At least you can create a style and check yours to find differences and learn how to edit your ActionBar.

How to customize Action Bar Style?

How to change the color of Action Bar Back Button and Action bar Menu Icon(Image attached).
I have the following style code(below), using which I customized the Text but I'm not able to completely customize the Action Bar.
Below is the Style code which I have used :
<style name="MyCustomTheme" parent="Theme.Sherlock.Light">
<item name="actionBarStyle">#style/ActionBar</item>
<item name="android:actionBarStyle">#style/ActionBar</item>
</style>
<style name="ActionBar" parent="Widget.Sherlock.ActionBar">
<item name="background">#drawable/bg_header</item> -----------(1)
<item name="android:background">#drawable/bg_header</item>
<item name="android:titleTextStyle">#style/customTextAppearance.Sherlock.Widget.ActionBar.Title</item> ----(2)
<item name="titleTextStyle">#style/customTextAppearance.Sherlock.Widget.ActionBar.Title</item>
<item name="android:homeAsUpIndicator">#style/customTextAppearance.Sherlock.Widget.ActionBar.Title</item>
</style>
<style name="customTextAppearance.Sherlock.Widget.ActionBar.Title" parent="TextAppearance.Sherlock.Widget.ActionBar.Title">
<item name="android:textSize">18dp</item>
<item name="android:textColor">#ffffff</item>
<item name="android:shadowColor">#ffffff</item>
<item name="android:shadowDy">3</item>
<item name="android:textStyle">bold</item>
</style>
Your help will be appreciated, Thank you.
Just find proper icons for your actionbar and customize it...
and then make changes in your...
You Can Do Following For Changing Icons Of Actionbar
style.xml
<style name="Widget.ActionButton.Overflow" parent="#android:style/Widget.Holo.ActionButton.Overflow">
<item name="android:src">#drawable/ic_action_overflow</item>
</style>
<style name="Your.Theme" parent="#android:style/Theme.Holo.Light.DarkActionBar">
<item name="android:actionOverflowButtonStyle">#style/Widget.ActionButton.Overflow</item>
<item name="android:homeAsUpIndicator">#drawable/my_fancy_up_indicator</item>
</style>
check out this page on android help https://developer.android.com/training/basics/actionbar/styling.html
When supporting Android 3.0 and higher only,
you can define the action bar's background like this: res/values/themes.xml
<?xml version="1.0" encoding="utf-8"?>
<resources>
<!-- the theme applied to the application or activity -->
<style name="CustomActionBarTheme"
parent="#android:style/Theme.Holo.Light.DarkActionBar">
<item name="android:actionBarStyle">#style/MyActionBar</item>
</style>
<!-- ActionBar styles -->
<style name="MyActionBar"
parent="#android:style/Widget.Holo.Light.ActionBar.Solid.Inverse">
<item name="android:background">#drawable/actionbar_background</item>
</style>
</resources>
Then apply your theme to your entire app or individual activities:
<application android:theme="#style/CustomActionBarTheme" ... />
For Android 2.1 and higher
When using the Support Library, the same theme as above must instead look like this:
res/values/themes.xml
<?xml version="1.0" encoding="utf-8"?>
<resources>
<!-- the theme applied to the application or activity -->
<style name="CustomActionBarTheme"
parent="#style/Theme.AppCompat.Light.DarkActionBar">
<item name="android:actionBarStyle">#style/MyActionBar</item>
<!-- Support library compatibility -->
<item name="actionBarStyle">#style/MyActionBar</item>
</style>
<!-- ActionBar styles -->
<style name="MyActionBar"
parent="#style/Widget.AppCompat.Light.ActionBar.Solid.Inverse">
<item name="android:background">#drawable/actionbar_background</item>
<!-- Support library compatibility -->
<item name="background">#drawable/actionbar_background</item>
</style>
</resources>
Then apply your theme to your entire app or individual activities:
<application android:theme="#style/CustomActionBarTheme" ... />

Categories

Resources