I am trying to style background for action bar for versions 2.2 >=. I want to have dark red on title bar and lighter red on tabs. I have similar file placed in values-v11 and values-v14 accordingly. It works as intended on ICS and Kitkat I tested. On 2.x, the color on backgroundStacked appears on both the title bar and tabs.
Why is this happening? I don't want to use Android Asset Studio because I don't want to add extra images if it is possible without.
res/values/styles.xml
<style name="MyAppTheme" parent="#style/Theme.AppCompat.Light.DarkActionBar">
<item name="actionBarStyle">#style/MyActionBar</item>
</style>
<style name="MyActionBar" parent="#style/Widget.AppCompat.ActionBar.Solid">
<item name="background">#color/dark_red</item>
<item name="backgroundStacked">#color/lighter_red</item>
<item name="titleTextStyle">#style/MyActionBarTabText</item>
</style>
<style name="MyActionBarTabText" parent="#style/TextAppearance.AppCompat.Widget.ActionBar.Title">
<item name="android:textColor">#color/white</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've just updated my project to target API 22, and my action bar style appears to have broken. Despite setting the background to white, and the color to blue, I end up with a black action bar with white text.
Here's my application theme.
<style name="AppTheme" parent="AppBaseTheme">
<!-- All customizations that are NOT specific to a particular API-level can go here. -->
<item name="android:actionBarStyle">#style/MyActionBar</item>
<item name="android:homeAsUpIndicator">#drawable/up_button</item>
<item name="android:actionMenuTextAppearance">#style/H4.Other</item>
<item name="android:actionMenuTextColor">#color/h4_other</item>
<item name="android:windowContentOverlay">#drawable/header_shadow</item>
<item name="android:buttonStyle">#style/ButtonStyle.NoCaps</item>
</style>
Here's my action bar style.
<style name="MyActionBar" parent="#android:style/Widget.Holo.Light.ActionBar">
<item name="android:title">""</item>
<item name="android:background">#color/white</item>
<item name="android:height">#dimen/action_bar_height</item>
<item name="android:titleTextStyle">#style/H5.Blue</item>
</style>
Ok I figured this out. When you've updated the version of the app compat library you're using, the namespacing of some attributes needs to change. In my case it was changing from android:background to just background, among other things.
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!
I'm working with the new Lollipop Material Design guidelines and would like to incorporate that nifty navigation drawer animation in my app. I've gotten that far, by using the android.support.v7.app.ActionBarDrawerToggle, but now I'm having difficulty changing the color of said action bar. It stays bright gray no matter what I set the theme to. How would one go about changing the color of the actionbar? This is what my app theme looks like:
//res/values/styles.xml
<style name="AppTheme" parent="#style/Theme.AppCompat.Light.DarkActionBar">
<item name="android:actionBarStyle">#style/ActionBar</item>
<item name="android:colorPrimary">#color/primaryDef</item>
<item name="android:colorPrimaryDark">#color/primaryDarkDef</item>
<item name="android:activatedBackgroundIndicator">#drawable/defbg</item>
<item name="android:colorAccent">#color/primaryDef</item>
<item name="android:navigationBarColor">#color/primaryDarkDef</item>
</style>
<style name="ActionBar" parent="android:Widget.ActionBar">
<item name="android:background">#color/primaryDef</item>
</style>
AppCompat does not use the android: prefixed attributes for the Material Theme color palette items per the migration guide to v21 by the author of AppCompat. Instead, just use the names themselves:
<style name="AppTheme" parent="#style/Theme.AppCompat.Light.DarkActionBar">
<item name="colorPrimary">#color/primaryDef</item>
<item name="colorPrimaryDark">#color/primaryDarkDef</item>
<item name="colorAccent">#color/primaryDef</item>
<item name="android:navigationBarColor">#color/primaryDarkDef</item>
<item name="android:activatedBackgroundIndicator">#drawable/defbg</item>
</style>
The Action Bar will be colored by colorPrimary.
My app's theme looks like shown in the following screenshot:
As the theme is based on Theme.Holo.Light which contains dark action bar texts and overflow icon, I adjusted the overflow icon using the following style:
<style name="ActionBar.Light" parent="android:style/Widget.Holo.ActionBar">
<item name="android:background">#color/highlight</item>
<item name="android:titleTextStyle">#style/TextAppearance.ActionBar.Title.Light</item>
<item name="android:subtitleTextStyle">#style/TextAppearance.ActionBar.Subtitle.Light</item>
</style>
...
<style name="Theme.Light" parent="#android:style/Theme.Holo.Light">
...
<item name="android:actionBarStyle">#style/ActionBar.Light</item>
<item name="android:actionOverflowButtonStyle">#android:style/Widget.Holo.ActionButton.Overflow</item>
...
</style>
When one or more list entries are checked I want to show a white contextual action bar, but unfortunately the white overflow icon isn't visible on the white background:
Any idea on how to change the overflow icon only for the contextual bar -- either via style or programatically?
Final Workaround (February 27 2014)
It seems as there isn't an option to change the overflow icon of the contextual action bar independent from the one of the standard action bar. So I had no other choice but changing the background color of the contextual bar to a dark gray, to make the white overflow button visible:
The icons on the right are under my control, so it was easy to change them. The "done" icon on the left and the text (check counter) can easily be changed using theme attributes. Only the thin separator between the "done" icon and the check counter cannot be changed using attributes. They would require a custom layout -- that's why I left it how it is for now.
Here's my contextual bar style and the relevant part from the theme:
<style name="TextAppearance.ActionBar.Title" parent="#android:style/TextAppearance.Holo.Widget.ActionBar.Title">
<item name="android:fontFamily">sans-serif-light</item>
</style>
<style name="TextAppearance.ActionBar.Title.Light">
<item name="android:textColor">#ffffff</item>
</style>
<style name="ContextualBar.Light" parent="android:style/Widget.Holo.ActionMode">
<item name="android:background">#666666</item>
<item name="android:titleTextStyle">#style/TextAppearance.ActionBar.Title.Light</item>
<item name="android:actionMenuTextColor">#ffffff</item>
</style>
<style name="Theme.Light" parent="#android:style/Theme.Holo.Light">
...
<item name="android:actionBarStyle">#style/ActionBar.Light</item>
<item name="android:actionModeStyle">#style/ContextualBar.Light</item>
<item name="android:actionModeCloseDrawable">#drawable/ic_action_done</item>
<item name="android:actionOverflowButtonStyle">#android:style/Widget.Holo.ActionButton.Overflow</item>
<item name="android:actionMenuTextColor">#ffffff</item>
...
</style>
Ads: You can see the full result in the final app "uPod" which is available at Google play!
On your theme and assuming your using Appcompat
<style name="AppTheme" parent="Theme.AppCompat.NoActionBar">
<item name="android:actionOverflowButtonStyle">#style/OverFlowStyle</item>
</style>
<style name="OverFlowStyle" parent="Widget.AppCompat.ActionButton.Overflow">
<item name="android:src">#drawable/your_selector_drawable_here</item>
</style>