Android: Can't style ActionBar menu text - android

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>

Related

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.

can't change color of actionBar divider

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>

ActionBarDisappearing on Android 4.0+

I am currently writing an application for devices on 2.3 - 4.2+ and am having some weird, and unexpected issues. It was working fine until and displaying on all devices before I attempted to theme it. Even with a simple style simply extending the action bar sherlock theme, there appears to be no action bar showing.
The setup for the styles.
<style name="FrameworkRoot.Theme" parent="Theme.Sherlock.Light.DarkActionBar">
<!-- API 11+ (compatibility) -->
<item name="buttonBarStyle">#style/Compat.ButtonBar</item>
<item name="buttonBarButtonStyle">#style/Compat.ButtonBarButton</item>
<item name="indeterminateProgressStyle">#style/Compat.IndeterminateProgress</item>
<!-- API 14+ (compatibility) -->
<item name="listPreferredItemPaddingLeft">#dimen/compat_list_preferred_item_padding_left</item>
<item name="listPreferredItemPaddingRight">#dimen/compat_list_preferred_item_padding_right</item>
<item name="listPreferredItemHeightSmall">#dimen/compat_list_preferred_item_height_small</item>
</style>
<style name="Theme.Base" parent="FrameworkRoot.Theme">
<item name="textHeaderMaxLines">#integer/text_header_max_lines</item>
<item name="trackAbstractMaxLines">#integer/track_abstract_max_lines</item>
<item name="activatableItemBackground">#drawable/activatable_item_background</item>
</style>
<!-- Base themes for the app -->
<style name="Theme.TestApp" parent="Theme.Base">
<item name="actionBarStyle">#style/Widget.TestApp.ActionBar</item>
<item name="android:actionBarStyle">#style/Widget.TestApp.ActionBar</item>
</style>
<!-- Base Action Bar Style -->
<style name="Widget.TestApp.ActionBar" parent="Theme.Sherlock.Light.DarkActionBar">
</style>
If I remove the:
<item name="android:actionBarStyle">#style/Widget.TestApp.ActionBar</item>
So that the action bar itself it not getting styled in 3.0+, I can't style the bar.
What would be the best way to set this up? AndroidManifest.xml is pointing the app's style at "Theme.TestApp".
My end goal is to have a custom background on the action bar, as well as custom tab selector colors and fonts. What would be the best way to go about this, as my current method isn't working well.
You have to set an attribute for ActionBarSherlock and the native ActionBar. So replace this for example:
<style name="Theme.Base" parent="FrameworkRoot.Theme">
<item name="textHeaderMaxLines">#integer/text_header_max_lines</item>
<item name="trackAbstractMaxLines">#integer/track_abstract_max_lines</item>
<item name="activatableItemBackground">#drawable/activatable_item_background</item>
</style>
With this:
<style name="Theme.Base" parent="FrameworkRoot.Theme">
<item name="textHeaderMaxLines">#integer/text_header_max_lines</item>
<item name="trackAbstractMaxLines">#integer/track_abstract_max_lines</item>
<item name="activatableItemBackground">#drawable/activatable_item_background</item>
<item name="android:textHeaderMaxLines">#integer/text_header_max_lines</item>
<item name="android:trackAbstractMaxLines">#integer/track_abstract_max_lines</item>
<item name="android:activatableItemBackground">#drawable/activatable_item_background</item>
</style>
The attributes with the 'android' prefix point to the internal resources for the native ActionBar, the attributes without the 'android' in front point to the resources of the ActionBarSherlock.

Fully transparent ActionBarSherlock by using theme

I am using ActionBarSherlock 4.0.2.
I need a fully transparent action bar (without the neon color bottom divider). Hence, I have the following style:
<style name="AppTheme" parent="#style/Theme.Sherlock">
<item name="windowActionBarOverlay">true</item>
<item name="icon">#drawable/ic_home</item>
<item name="titleTextStyle">#style/ActionBarCompatTitle</item>
<item name="android:windowFullscreen">true</item>
</style>
By using above code, I will still have the following effect.
In order to disable the background, I put the following code in SherlockFragmentActivity#onCreate. Then the problem gone.
getSupportActionBar().setBackgroundDrawable(null);
However, I would like to see the solution being implemented in styles.xml instead of Java code, as I have many other devices with different screen configuration. I modified the styles.xml to the following, without using the previously mentioned fix in the Java code.
<style name="AppTheme" parent="#style/Theme.Sherlock">
<item name="windowActionBarOverlay">true</item>
<item name="icon">#drawable/ic_home</item>
<item name="titleTextStyle">#style/ActionBarCompatTitle</item>
<item name="android:windowFullscreen">true</item>
<item name="android:background">#drawable/transparent</item>
<item name="background">#drawable/transparent</item>
</style>
However, the neon divider still visible. It seems that my fix using android:background and background does not work. Am I missing something?
<style name="AppTheme" parent="#style/Theme.Sherlock">
<item name="actionBarStyle">#style/AppTheme.ActionBar</item>
<item name="android:actionBarStyle">#style/AppTheme.ActionBar</item>
</style>
<style name="AppTheme.ActionBar" parent="#style/Widget.Sherlock.ActionBar">
<item name="background">#android:color/transparent</item>
<item name="android:background">#android:color/transparent</item>
</style>

Style Inheritance with ActionBar Tab troubles

Many of my questions about "styling" actionbar tabs were answered by adamp in this thread on tab style, but I am still struggling with my arriving at the desired presentation.
Specifically, I am attempting to do what adamp suggested in the following fragment from my styles.xml file, but, I cannot get the inherited (Widget.holo.actionbar) feature of a light blue line to appear under the selected tab nor is there any indication of selection:
<style name="MyTheme" parent="android:style/Theme.Holo">
<item name="android:actionBarStyle">#style/CustomActionBar</item>
</style>
<style name="CustomActionBar" parent="android:style/Widget.Holo.ActionBar">
<item name="android:actionBarTabTextStyle">#style/customActionBarTabTextStyle</item>
<item name="android:actionBarTabStyle">#style/customActionBarTabStyle</item>
<item name="android:actionBarTabBarStyle">#style/customActionBarTabBarStyle</item>
</style>
<style name="customActionBarTabTextStyle" parent="#style/CustomActionBar">
<item name="android:textColor">#2966c2</item>
<item name="android:textSize">20sp</item>
<item name="android:typeface">sans</item>
</style>
<style name="customActionBarTabStyle" parent="#style/CustomActionBar">
<!-- <item name="android:background">#drawable/actionbar_tab_bg</item> -->
<item name="android:paddingLeft">20dp</item>
<item name="android:paddingRight">20dp</item>
</style>
<style name="customActionBarTabBarStyle" parent="#style/CustomActionBar">
<item name="android:paddingLeft">240dp</item>
</style>
Can someone explain why the thin blue line selection behavior of the Honeycomb Gallery Sample App does not work for me?
New insight since this was written: the problem here, I think, is that the style I have created to overide ActionBarTabStyle is entirely bogus:
<style name="customActionBarTabStyle" parent="#style/CustomActionBar">
<item name="android:paddingLeft">20dp</item>
<item name="android:paddingRight">20dp</item>
</style>
I need to specify the correct parent of this style per "Theme.holo"....how can one find where the default style is so it can be specified as a parent?
Thanks
To specify the correct parents for actionbar style in API 11, Check doc here:
https://developer.android.com/training/basics/actionbar/styling.html

Categories

Resources