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.
Related
I am trying to modify my app to have a dark blue action bar with a light blue background. So far I have only been able to make the entire app dark blue. How can I modify my code to keep the action bar the color it is now but make the background with the team numbers a light blue? Please note my apps minimum API is 14.
I am currently using the following code in my styles.xml:
<!-- Base application theme. -->
<style name="AppTheme" parent="Theme.AppCompat.Light.DarkActionBar">
<item name="android:background">#color/teamLightBlue</item>
</style>
<!-- Activity themes -->
<style name="Theme.Base" parent="android:Theme.Light" />
<style name="Theme.Sample" parent="Theme.Base" />
<!-- the theme applied to the application or activity -->
<style name="CustomActionBarTheme"
parent="AppTheme">
<item name="android:actionBarStyle">#style/MyActionBarTheme</item>
</style>
<!-- ActionBar styles -->
<style name="MyActionBarTheme" parent="#android:style/Widget.Holo.Light.ActionBar">
<item name="android:background">#color/teamDarkBlue</item>
</style>
If you choose to use Theme.AppCompat, you can change Action Bar's background color using:
<item name="colorPrimary">#ffffff</item>
but if you choose the Holo one, you can change that color using
<item name="android:colorPrimary">#ffffff</item>
Hope this helps.
As far as I know your code is good instead of Widget.Holo.Light.ActionBar as its not part of AppCompat v7. Use this instead
<style name="CustomActionBarTheme" parent="AppTheme">
<item name="android:actionBarStyle" tools:ignore="NewApi">#style/MyActionBarTheme</item>
<item name="actionBarStyle">#style/MyActionBarTheme</item>
</style>
<style name="MyActionBarTheme" parent="#style/Widget.AppCompat.Light.ActionBar.Solid.Inverse">
<item name="android:background">#color/teamDarkBlue</item>
<item name="background">#color/teamDarkBlue</item>
</style>
It should work fine!
Now I make app with SDK 22,but the Action Bar's app icon dispear.
Here are my code.
<resources>
<!-- Base application theme. -->
<style name="AppTheme" parent="Theme.AppCompat.Light.DarkActionBar">
<!-- Customize your theme here. -->
<item name="android:actionBarStyle">#style/ActionBar</item>
<item name="actionBarStyle">#style/ActionBar</item>
<item name="actionOverflowButtonStyle">#style/overflowButton</item>
</style>
<!--ActionBar-->
<style name="ActionBar" parent="#style/Widget.AppCompat.Light.ActionBar.Solid.Inverse">
<item name="android:background">#color/bg</item>
<item name="background">#color/bg</item>
<item name="android:title">#string/test</item>
<item name="title">#string/test</item>
<item name="icon">#mipmap/ic_launcher</item> <!-- here I want to show the app icon,but it can't-->
<item name="android:icon">#mipmap/ic_launcher</item>
</style>
<style name="overflowButton">
<item name="android:src">#mipmap/ic_add_black_48dp</item>
<item name="android:showAsAction"></item>
</style>
<style name="NoActionBarTheme" parent="Theme.AppCompat.Light.NoActionBar"></style>
</resources>
I have try to solve it by android deceloper,but fail.I also try many other ways,it also fail.Please help me .
As per my understanding, your main issue is that application icon do not appear on actionbar.
For that you need to set display option to actionbar.
getSupportActionBar().setDisplayOptions(ActionBar.DISPLAY_SHOW_HOME | ActionBar.DISPLAY_SHOW_TITLE);
getSupportActionBar().setIcon(R.drawable.ic_launcher);
PS you need to import android.support.v7.app.ActionBar to your activity.
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.
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>
I'm trying to create a new theme and customize the action bar:
<resources>
<style name="Theme.Shappy.Red" parent="Theme.Sherlock.Light">
<item name="android:actionBarStyle">#style/ActionBar.Shappy.Red</item>
...
... [some_other_customizations]
</style>
<!-- Action bar -->
<style name="ActionBar.Shappy.Red" parent="#style/Widget.Sherlock.Light.ActionBar.Solid">
<item name="android:background">#ffb70000</item>
<item name="android:titleTextStyle">#style/ActionBar.Title.Shappy.Red</item>
</style>
<!-- Action bar text -->
<style name="ActionBar.Title.Shappy.Red" parent="#style/TextAppearance.Sherlock.Widget.ActionBar.Title">
<item name="android:textColor">#ddffffff</item>
</style>
</resources>
As you can see, I'm using Sherlock. This code works fine for API level 14, but it doesn't work for API level 10. I still see the Holo light like action bar.
I think the code is correct because [some_other_customizations] are applied correctly.
Do you have any suggestion? Thanks.
<item name="android:actionBarStyle">#style/ActionBar.Shappy.Red</item>
and everything else with "android:" infront of it applies to the default actionbar. You have to put this in your styles as well:
<item name="actionBarStyle">#style/ActionBar.Shappy.Red</item>
This overrides the styles of the ABS.
So your Styles should look like this in order to work in API Levels 13<:
<style name="Theme.Shappy.Red" parent="Theme.Sherlock.Light">
<item name="android:actionBarStyle">#style/ActionBar.Shappy.Red</item>
<item name="actionBarStyle">#style/ActionBar.Shappy.Red</item>
</style>
<!-- Action bar -->
<style name="ActionBar.Shappy.Red" parent="#style/Widget.Sherlock.Light.ActionBar.Solid">
<item name="android:background">#ffb70000</item>
<item name="background">#ffb70000</item>
<item name="android:titleTextStyle">#style/ActionBar.Title.Shappy.Red</item>
<item name="titleTextStyle">#style/ActionBar.Title.Shappy.Red</item>
</style>
<!-- Action bar text -->
<style name="ActionBar.Title.Shappy.Red" parent="#style/TextAppearance.Sherlock.Widget.ActionBar.Title">
<item name="android:textColor">#ddffffff</item>
<item name="textColor">#ddffffff</item>
</style>