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>
Related
I am trying to style the overflow menu items on the action bar but so far I've had no luck. I am testing on Android API 21 but my minimum version is set to 17. I am using the theme DeviceDefault. I tried setting the theme to Holo but the action bar disappears completely then. Anyways, here are the styles I'm currently using for the action bar:
<style name="AppBaseTheme" parent="android:Theme.DeviceDefault">
<item name="android:popupMenuStyle">#style/PopupMenu</item>
<item name="android:actionBarStyle">#style/MyActionBar</item>
<item name="actionBarStyle">#style/MyActionBar</item>
<item name="android:displayOptions">showHome|useLogo|showTitle</item>
</style>
<style name="AppTheme" parent="AppBaseTheme">
</style>
<style name="MyActionBar">
<item name="android:background">#drawable/gradient3</item>
<item name="android:titleTextStyle">#style/MyActionBarTitleText</item>
<item name="titleTextStyle">#style/MyActionBarTitleText</item>
</style>
<style name="PopupMenu" parent="android:Widget.DeviceDefault.ListPopupWindow">
<item name="android:popupBackground">#drawable/gradient1</item>
<item name="android:textColor">#color/ed</item>
</style>
<style name="MyActionBarTitleText" parent="#style/TextAppearance.AppCompat.Widget.ActionBar.Title">
<item name="android:textColor">#color/ed</item>
<item name="android:textSize">18sp</item>
</style>
So far popupMenuStyle seems to be ignored on API 21 but the action bar background takes effect. What is the correct way of styling the overflow menu for android versions 17 onwards? Also, is it recommended to use DeviceDefault as the theme and if not, is there a reason the Holo theme is making the action bar disappear?
Thank you. I appreciate any help.
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 trying to change the background of the action bar via xml, but the action bar is not shown anymore at all.
This is the style that I am using, declared in styles.xml:
<style name="AppBaseTheme" parent="#style/Theme.AppCompat.Light.DarkActionBar">
<item name="actionBarStyle">#style/DiaryActionBar</item>
<item name="android:actionBarStyle">#style/DiaryActionBar</item>
</style>
<style name="DiaryActionBar"
parent="#style/Theme.AppCompat.Light.DarkActionBar">
<item name="background">#color/action_bar_bg</item>
<item name="android:background">#color/action_bar_bg</item>
</style>
I have set both android:background and background for compatibility. This is the only styles.xml file in my app. What am I doing wrong?
In my style with custom actionbar background, i have this:
<style name="Theme.Malaka" parent="#style/Theme.AppCompat">
<style name="Malaka.ActionBar" parent="#style/Widget.AppCompat.ActionBar">
And that works just fine. Items of the styles are the same as yours. Please note that the parent of Malaka.ActionBar is not Theme... but Widget...
For changing background and actionBarStyle from android styling.You can do like this..
<style name="AppBaseTheme" parent="#android:style/Theme.Black">
<item name="android:actionBarStyle">#style/Theme.DeviceDefault.NoActionBar</item>
</style>
<style name="DiaryActionBar" parent="#android:style/Theme.Black">
<item name="android:background">#color/action_bar_bg</item>
</style>
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.