ActionBar styling different tab background when below ActionBar - android

Is there a way to define ActionBar tab style so that it would have different backgrounds when tabs are in ActionBar and below it?
I can't seem to find a way to do that with theme configuration with these properties
<item name="android:actionBarTabStyle">#style/Custom.ActionBar.TabView</item>
<item name="android:actionBarTabBarStyle">#style/Custom.ActionBar.TabBar</item>
<item name="android:actionBarTabTextStyle">#style/Custom.ActionBar.TabText</item>
I can define tab background to be white in #style/Custom.ActionBar.TabBar. All is ok with ActionBar.NAVIGATION_MODE_TABS.
But when I switch to ActionBar.NAVIGATION_MODE_LIST it is placed inside ActionBar and it also becomes white. And thats is unwanted behavior.

You can control the behaviors and visibility of the action bar with the ActionBar APIs, which were added in Android 3.0 (API level 11)."
So, ActionBar will not work for your target environment which is at API level 10 (Android 2.3.3).
Just in case, if you target for minimum API level 11 , you can change ActionBar's background color by defining custom style, as:
<resources>
<style name="MyTheme" parent="#android:style/Theme.Holo.Light">
<item name="android:actionBarStyle">#style/MyActionBar</item>
</style>
<style name="MyActionBar" parent="#android:style/Widget.Holo.Light.ActionBar">
<item name="android:background">ANY_HEX_COLOR_CODE</item>
</style>
</resources>
And, set "MyTheme" as theme for application / activity.
Hope this helps...

Related

Change color of actionbar [duplicate]

This question already has an answer here:
Change Android 5.0 Actionbar color
(1 answer)
Closed 7 years ago.
I have looked through the Android examples online and perused through all the available documentation, but am still befuddled. I am targeting version 19 of the Android SDK as minSDK. All I need to do is to change the background color of the actionbar. My code for some reason does not seem to work.
I want the window background color of the rest of the app to be white.
I want the background of the actionbar to be blue.
Below is my resources file:
<resources>
<!-- Base application theme. -->
<style name="AppTheme" parent="Theme.AppCompat.Light">
<item name="android:windowBackground">#android:color/white</item>
<item name="android:actionBarStyle">#style/post_action_bar</item>
</style>
<style name="post_action_bar" parent="#android:style/Widget.Holo.Light.ActionBar">
<item name="android:background">#android:color/holo_blue_dark</item>
<item name="android:backgroundStacked">#android:color/holo_blue_dark</item>
<item name="android:backgroundSplit">#android:color/holo_blue_dark</item>
<item name="android:windowActionBar">true</item>
<item name="android:windowNoTitle">false</item>
</style>
</resources>
This does not work. The rest of the app is white, but my bar has a grayish color.
You can try to set programatically in code like
ActionBar ab = getActionBar();
ab.setBackgroundDrawable(new ColorDrawable(Color.parseColor("#000000")));
It's as easy as adding this to your AppTheme
<!-- colorPrimary is used for the default action bar background -->
<item name="colorPrimary">#color/my_awesome_color</item>
Note: this will work pre-lolipop as long as your theme's parent is from Theme.AppCompat and your support library is atleast v21, so if you havent already update the support lib to the latest which at this time is v23.0.1 (i think)
compile 'com.android.support:appcompat-v7:23.0.1'
Read this if you want to learn more about styling your ActionBar, and more
https://developer.android.com/training/basics/actionbar/styling.html
Here you have everything explained in detail about styling the Action Bar.
Best regards

Change background color of Android Action Bar

I have an Activity with an action bar. minSdkVersion is 11.
The action bar is a grey color, I would like to change it to a different color so that it matches other colors in my application.
I have created the following styles
<style name="MyTheme" parent="#android:style/Theme.Holo.Light">
<item name="android:actionBarStyle">#style/MyActionBar</item>
</style>
<style name="MyActionBar" parent="#android:style/Widget.Holo.Light.ActionBar">
<item name="android:background">#FFF</item>
</style>
And set this activity's theme in the appmanifest to MyTheme but when I run the application I get this error:
You need to use a Theme.AppCompat theme (or descendant) with this activity.
What am I doing wrong?
See https://developer.android.com/training/basics/actionbar/styling.html, specifically these parts
Note: If you are using the Support Library APIs for the action bar,
then you must use (or override) the Theme.AppCompat family of styles
(rather than the Theme.Holo family, available in API level 11 and
higher)
and
When using the Support Library, you must instead use the Theme.AppCompat themes:
Theme.AppCompat for the "dark" theme.
Theme.AppCompat.Light for the "light" theme.
Theme.AppCompat.Light.DarkActionBar for the light theme
with a dark action bar.
Basically you have to replace 'Holo' with 'AppCompat'
If you are using ActionBarActivity, you need to use an AppCompat theme, which brings the Lollipop style Action Bars to all devices and support for the Material Color Palette allowing you to write a theme such as
<style name="MyTheme" parent="#android:style/Theme.AppCompat.Light">
<item name="ColorPrimary">#color/primary</item>
</style>
to style your action bar color automatically.
If you'd prefer to not use any of that (and look very different on Lollipop devices), you can instead extend FragmentActivity or Activity, depending on if you want to use the support library fragments (which backport and fix a number of issues around nested fragments and state saving).
Just use this, if your extending ActivityActionBar on your activity then you need to use the AppCompat themes.
<style name="AppCompatTheme" parent="#android:style/Theme.AppCompat.Light">
<item name="ColorPrimary">#color/primary</item>
</style>
or use style/Theme.AppCompat.Dark for white text :)

Custom theme for a dark actionbar / tab bar

I am trying to set a custom actionbar for my app like so
<style name="AppBaseTheme" parent="android:Theme.Holo.Light.DarkActionBar">
<!-- API 11 theme customizations can go here. -->
<item name="android:actionMenuTextColor">#FFFFFF</item>
<item name="android:actionBarWidgetTheme">#style/MyActionWidgetTheme</item>
<item name="android:actionBarStyle">#style/BasicActionBar</item>
</style>
<style name="BasicActionBar" parent="android:Widget.Holo.ActionBar">
<item name="android:background">#color/red</item>
</style>
when i don't include
<item name="android:actionBarStyle">#style/BasicActionBar</item>
The actionbar and tab bar appear dark but i want to set the actionbar's color and keep the tabs dark. When i set the style the action bar changes color but the tabs turn to white.
I am pretty sure the problem is
parent="android:Widget.Holo.ActionBar"
I have tried any bunch of different possible values for this but can't find one that keeps the tab bar dark
this link helped me http://jgilfelt.github.io/android-actionbarstylegenerator/
#style/Widget.Sherlock.Light.ActionBar.Solid.Inverse
did the trick

How can I have a drop shadow on my ActionBar (ActionBarSherlock)?

I am including my styled xml layout:
<resources xmlns:android="http://schemas.android.com/apk/res/android">
<style name="Theme.Styled" parent="Theme.Sherlock">
<item name="actionBarStyle">#style/Widget.MyApp.ActionBar</item>
<item name="android:actionBarStyle">#style/Widget.MyApp.ActionBar</item>
</style>
<style name="Widget.MyApp.ActionBar" parent="Widget.Sherlock.Light.ActionBar">
<item name="titleTextStyle">#style/Widget.MyApp.TitleTextStyle</item>
<item name="background">#color/red</item>
<item name="android:background">#color/red</item>
<item name="windowContentOverlay">#null</item>
<item name="android:windowContentOverlay">#null</item>
</style>
<style name="Widget.MyApp.TitleTextStyle" parent="TextAppearance.Sherlock.Widget.ActionBar.Title">
<item name="android:textColor">#color/white</item>
<item name="android:textSize">21sp</item>
</style>
</resources>
Some of the search over internet suggests that use windowContentOverlay set to #null. But when i use it in the style xml it doesn't change anything. Can any one help what to do?
If you want to create a shadow below the ActionBar you have to set android:windowContentOverlay parameter on the application theme (in your code you are incorrectly setting it on the ActionBar style).
In your example it would be:
<style name="Theme.Styled" parent="Theme.Sherlock">
...
<item name="android:windowContentOverlay">#drawable/my_actionbar_shadow</item>
</style>
Using #null value removes the shadow.
This one line sets the shadow on ActionBar on Android 3.0 and newer. However if you are using ActionBarSherlock, it will not work as you expect. It would create the shadow on top of the window over the ActionBarSherlock on Android devices running system older than Android 4.0 (although ActionBar is present in the api since Android 3.0, ActionBarSherlock uses custom implementation for all Android versions older than Android 4.0).
To create the shadow below ActionBarSherlock you have to set windowContentOverlay parameter on the application theme (notice the missing android:).
<style name="Theme.Styled" parent="Theme.Sherlock">
...
<item name="windowContentOverlay">#drawable/my_actionbar_shadow</item>
</style>
Again, using #null removes the shadow.
Although this line works for ActionBarSherlock, it doesn't work on android devices running Android 4.0 and newer, no shadow is created under the ActionBar on such devices. So how to combine these two parameters to get the desired shadow under both ActionBar and ActionBarSherlock?
Use resource configuration qualifiers, in your case use platform version qualifiers.
In res/values/styles.xml use the second xml code. And in res/values-v14/styles.xml use the first xml code. Therefore the ActionBarSherlock version is used by default (for versions pre Android 4.0) and ActionBar version is used for Android 4.0 and newer.
Edit:
There is a bug in Android 4.3 (API level 18), android:windowContentOverlay does not work. It should be fixed in future release. In case you need it fixed in Android 4.3, you can find workarounds linked in the bug report.
As a previous answer did say use "windowContentOverlay" in the application theme and NOT the action bar style.
<style name="Theme.Styled" parent="Theme.Sherlock">
...
<item name="windowContentOverlay">#drawable/my_actionbar_shadow</item>
</style>
If you want a realistic shadow you can find one in the
"Your Android Folder"/platforms/android-16/data/res/drawable-hdpi/
ab_solid_shadow_holo.9.png and copy it to your drawable-hdpi folder then the end result is
<style name="Theme.Styled" parent="Theme.Sherlock">
...
<item name="windowContentOverlay">#drawable/ab_solid_shadow_holo</item>
</style>
In addition, above API21(Lollipop), you will need this in code, too.
getSupportActionBar().setElevation(0);

Android: ActionBar Hidden

I have an old app which now when run on tablets like the Xoom, hides the ActionBar. The app was written before the ActionBar existed so some old code is hiding the actionbar.
What in an old app can hide the ActionBar? I need to change it so that the ActionBar and therefore the menu can be shown:
Here's my very simple Theme:
<?xml version="1.0" encoding="utf-8"?>
<resources>
<style name="MyTheme" parent="android:Theme.Black">
<item name="android:windowNoTitle">false</item>
<item name="android:windowFullscreen">false</item>
<item name="android:windowContentOverlay">#android:color/transparent</item>
</style>
<style name="TextViewStyled" parent="#android:style/Widget.TextView">
<item name="android:textStyle">normal</item>
<item name="android:lineSpacingMultiplier">1.22</item>
</style>
</resources>
And here's the only window settings I use:
getWindow().requestFeature(Window.FEATURE_INDETERMINATE_PROGRESS);
requestWindowFeature(Window.FEATURE_RIGHT_ICON);
Using android:Theme.Black as your theme parent is what's "hiding" the action bar. The Holo and DeviceDefault theme families include an action bar by default, but the legacy theme family (from which Theme.Black derives) does not.
Use a theme declared with the same name "MyTheme" in res/values-v11/themes.xml with a parent of #android:style/Theme.Holo. This version of the theme will be used on devices running API level 11 (Android 3.0, where Holo and the action bar were introduced) or newer. You should similarly use Widget.Holo.TextView instead of Widget.TextView when declaring a custom view style to work within the Holo theme.

Categories

Resources