can't change color of actionBar divider - android

I tried change color of my actionBar divider , but nothing work. I' using android support library v7 for support old devices and custom style, and i also change all action bar drawable, but nothing happend!
<resources>
<style name="MyTheme" parent="Theme.AppCompat">
<item name="actionBarStyle">#style/MyActionBar</item>
</style>
<style name="MyActionBar" parent = "Widget.AppCompat.ActionBar">
<item name="background">#drawable/my_action_bar</item>
</style>
</resources>
And my ide show me strange error in layout , why did i get this error? it's not color value
java.lang.NumberFormatException: Color value '#drawable/abs__ab_transparent_dark_holo' must start with #
Solution: Need to add android namespace if use for api level >= 14 .May be it will be helpful to someone.

It is because the "divider" is an image. It's hardcoded in the Holo theme assets.
Look at platforms/android-19/data/res/drawable-xxhdpi/ab_transparent_dark_holo.9.png
The style is declared here for holo dark.
<style name="Widget.Holo.ActionBar" parent="Widget.ActionBar">
...
<item name="android:background">#android:drawable/ab_transparent_dark_holo</item>
...
</style>
It's a background. You will need to change the color in the image and replace the background of your bar.
It also needs different sizes for different resolutions.

Maybe you should set color directly, change your theme as
<item name="android:divider">#color/dividercolor</item>
Then you should add color dividercolor in you /value/color file,like
<item name="dividercolor"> #0099CC </item>

I hope this will be helpful to you
<style name="CustomTheme" parent="#android:style/Theme.Holo.Light">
<item name="android:actionBarStyle">#style/MyTheme.ActionBarStyle</item>
<item name="android:actionBarDivider">#drawable/action_vertical_doted</item>
<item name="android:actionButtonStyle">#style/MyTheme.ActionBar.ActionButton</item>
<item name="android:actionMenuTextColor">#ffffff</item>
<!-- <item name="android:actionMenuTextAppearance">#style/MyTheme.Menu.FontStyle</item> -->
<!-- <item name="android:actionBarSize">50dp</item> -->
</style>
<style name="MyTheme.ActionBarStyle" parent="#android:style/Widget.Holo.Light.ActionBar">
<item name="android:titleTextStyle">#style/MyTheme.ActionBar.TitleTextStyle</item>
<item name="android:background">#drawable/actionbar_bg_shap</item>
<item name="android:displayOptions">none</item>
<item name="android:backgroundSplit">#drawable/actionbar_bg_shap</item>
</style>
<style name="MyTheme.ActionBar.ActionButton" parent="#android:style/Widget.Holo.Light.ActionButton">
<item name="android:background">#drawable/main_button_inactive_tr</item>
</style>

Related

Android - Can't change action bar text colour

I'm trying to apply a custom style to the material theme action bar. Nothing fancy, just a simple change of title text colour, however I can't get the colour to change at all. I've set up a theme an app theme as follows in the themes xml:
<resources>
<style name="AppTheme" parent="Base.AppTheme">
<item name="android:navigationBarColor">?android:attr/colorPrimaryDark</item>
<item name="actionBarStyle">#style/AppBarLayout</item>
</style>
<style name="Base.AppTheme" parent="Theme.MaterialComponents.DayNight">
<item name="colorPrimary">#color/colorPrimary</item>
<item name="colorPrimaryVariant">#color/colorPrimaryDark</item>
<item name="colorPrimaryDark">#color/colorPrimaryDark</item>
<item name="colorSecondary">#color/colorSecondary</item>
<item name="colorSecondaryVariant">#color/colorSecondaryDark</item>
<item name="colorOnPrimary">#color/colorTextLight</item>
<item name="colorOnSecondary">#color/colorTextDark</item>
<item name="colorError">#color/colorError</item>
</style>
</resources>
The action bar style which is referenced is defined in the styles xml as:
<style name="AppBarLayout" parent="Widget.AppCompat.ActionBar">
<item name="background">?attr/colorPrimaryDark</item>
<item name="titleTextStyle">#style/AppBarText</item>
</style>
The style which titleTextStyle references is also defined in styles xml as:
<style name="AppBarText" parent="ThemeOverlay.AppCompat.Dark.ActionBar">
<item name="android:textColor">#color/colorError</item>
</style>
I've tried other attributes in the latter style, such as:
<item name="android:titleTextStyle">#color/colorError</item>
<item name="titleTextStyle">#color/colorError</item>
<item name="colorOnPrimary">#color/colorError</item>
<item name="android:textColorPrimary">#color/colorError</item>
I've also tried applying the AppBarText style with other attributes to titleTextStyle, such as android:textAppearance. Alas - no luck.
How can I get this to change? Perhaps I'm misunderstanding how Material components work?
I am not sure if this will work but try this code once:
int labelColor = getResources().getColor(R.color.label_color);
String сolorString = String.format("%X", labelColor).substring(2); // !!strip alpha value!!
Html.fromHtml(String.format("<font color=\"#%s\">text</font>", сolorString), TextView.BufferType.SPANNABLE);
getSupportActionBar().setTitle(colorString);

Android actionbar background around title

Android Studio 1.1.0. SDK 22 Installed&Compiled, SDK 17 Target (I suppose it's not relevant, because issue occurs also on preview in IDE).
I started playing with Holo theme action bar styling and ran into an issue, involving background color. This is my styles.xml:
<resources>
<style name="AppTheme" parent="android:Theme.Holo.Light.DarkActionBar">
<item name="android:background">#ff0d3200</item>
<item name="android:actionBarStyle">#style/BarTheme</item>
</style>
<style name="BarTheme" parent="android:Widget.Holo.ActionBar">
<item name="android:background">#443322</item>
</style>
</resources>
And this is output. I want app title's background color to be the same as action bar's. As I've said, it's the same on the preview, so I don't think it's because my phone(SDK17) or emulator. Overflow button behaves the same way, there just isn't any in this case.
I tried setting android:titleTextStyle in BarTheme to this style:
<style name="TitleTheme" parent="android:TextAppearance.Holo">
<item name="android:background">#443322</item>
</style>
But it didn't change a thing. What do I do to overcome this?
try ,
<style name="AppTheme" parent="android:Theme.Holo.Light.DarkActionBar">
<!-- All customizations that are NOT specific to a particular API-level can go here. -->
<item name="android:actionBarStyle">#style/MyActionBar</item>
</style>
<style name="MyActionBar" parent="#android:style/Widget.Holo.Light.ActionBar">
<item name="android:background">value</item>
<item name="android:titleTextStyle">#style/TitleColor</item>
</style>
<style name="TitleColor" parent="android:TextAppearance.Holo.Widget.ActionBar.Title">
<item name="android:textColor">value</item>
</style>
Due to David's input I solved my problem myself. I had to set windowBackground, instead of background in AppTheme. I'm not sure what is the exact difference, but it works properly. Remember not to change attribute in your BarTheme, because it won't work with windowBackground. Therefore correct styles.xml file is:
<resources>
<color name="bcColor">#ff0d3200</color>
<style name="AppTheme" parent="android:Theme.Holo.Light.DarkActionBar">
<item name="android:windowBackground">#color/bcColor</item>
<item name="android:actionBarStyle">#style/BarTheme</item>
</style>
<style name="BarTheme" parent="android:Widget.Holo.ActionBar">
<item name="android:background">#443322</item>
</style>
</resources>
Note that color has to be defined as resource in this case and cannot be hardcoded. The clean way to do this is create colors.xml in values folder and define all colors there.

Lollipop Theme issue

I am using sherlock action bar in my project, I have used Theme.Sherlock.Light.DarkActionBar
<style name="AppTheme" parent="Theme.Sherlock.Light.DarkActionBar">
<item name="android:homeAsUpIndicator">#drawable/transparent</item>
<item name="homeAsUpIndicator">#drawable/transparent</item>
<item name="actionBarStyle">#style/Widget.MyTheme.ActionBar</item>
<item name="android:actionBarStyle">#style/Widget.MyTheme.ActionBar</item>
<item name="android:titleTextStyle">#style/Widget.MyTheme.TitleTextStyle</item>
<item name="android:textAllCaps">false</item>
</style>
Problem :
I am getting light color menu with lollipop:
pre lollipop image :
Lollipop image :
can some one guide me, how can I get slimier menu color on both .
You can create a style which extends from actionbar sherlock to change color of you actionbar with other properties.
<style name="Theme.MyTheme" parent="Theme.Sherlock.ForceOverflow">
<item name="actionBarStyle">#style/Widget.MyTheme.ActionBar</item>
<item name="android:actionBarStyle">#style/Widget.MyTheme.ActionBar</item>
</style>
<style name="Widget.MyTheme.ActionBar" parent="Widget.Sherlock.ActionBar">
<item name="android:background">#ff000000</item>
<item name="background">#ff000000</item>
<item name="android:textColor">#CC3232</item>
</style>
For TextColor only
<style name="YOURTHEME.ActionBar.TitleTextStyle" parent="TextAppearance.Sherlock.Widget.ActionBar.Title">
<item name="android:textColor">#color/yourColor</item>
<item name="textColor">#color/yourColor</item>
</style>
Last resort Solution
<item name="android:textColorPrimary">#color/yourColor</item>
You should create a new styles.xml in a separate values-21 folder. There, you can define a specific theme/style that suits your needs for Lollipop devices only.
You should be using the ActionBar or ToolBar provided by app-compat library, instead of ActionBarSherlock.
ABS uses replacement Holo themes for older versions, which I guess hasn't been updated in a while.

Change color title bar

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)
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"
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>
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>
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();.
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.

Android: Can't style ActionBar menu text

I'm trying to create a custom styling for the ActionBar. Specifically i'm trying to change the menu item color.
I applied these stylings:
<style name="MyActionBar" parent="#style/Widget.Sherlock.Light.ActionBar">
<item name="android:actionMenuTextAppearance" tools:ignore="NewApi">#style/MyActionBarMenuText</item>
<item name="android:background">#drawable/actionbar_bg</item>
<!-- Support library compatibility -->
<item name="actionMenuTextAppearance">#style/MyActionBarMenuText</item>
<item name="background">#drawable/actionbar_bg</item>
</style>
<style name="MyActionBarMenuText" parent="#style/TextAppearance.Sherlock.Widget.ActionBar.Menu">
<item name="android:actionMenuTextColor" tools:ignore="NewApi">#color/actionbar_text</item>
<item name="actionMenuTextColor">#color/actionbar_text</item>
<!-- The textColor property is backward compatible with the Support Library -->
</style>
The background is applying but the menu text colour is not. What am i missing?
I know this was asked many times, but none of the solutions helped me.
Finally got it, Since android:actionMenuTextColor is defined in Theme.Sherlock.Light I needed to add it to my main custom theme which inherits from it and not to the style that inherits from Widget.Sherlock.Light.ActionBar:
<style name="MyTheme" parent="#style/Theme.Sherlock.Light">
<item name="android:actionBarStyle" tools:ignore="NewApi">#style/MyActionBar</item>
<item name="actionBarStyle">#style/MyActionBar</item>
<item name="android:actionMenuTextColor" tools:ignore="NewApi">#color/actionbar_text</item>
<item name="actionMenuTextColor">#color/actionbar_text</item>
</style>

Categories

Resources