ActionBar tabs height - android

I want to change default ActionBar tab's height, but can't find any info about. Is there some style attribute or method to set height of tabs?
Thanks.

You have to change the height of the actionbar in order to change the height of the tabs.
theme.xml
<style name="YourTheme" parent="#android:style/Theme.Holo">
<item name="android:actionBarTabStyle">#style/tab_nav</item>
<item name="android:actionBarTabTextStyle">#style/tab_nav_text</item>
<item name="android:actionBarSize">80dp</item>
..
</style>

This is how you style the tabs. Although, I was having trouble actually getting the height to change. I'm not sure you can set a height via a Style to the TabView. You may have to create custom View and apply that to your tabs in your code. All the styles and attributes you need to reference are in the SDK. Look in the Values folder of the platform version you're working with. That's how I typically find out how to do this.
<style name="Widget.Holo.Tab" parent="#android:style/Widget.Holo.Light.ActionBar.TabView">
<item name="android:height">#dp</item>
</style>
<style name="Your.Theme" parent="#android:style/Theme.Holo.Light">
<item name="android:actionBarTabStyle">#style/Widget.Holo.Tab</item>
</style>

Be Aware that using
android:theme="#android:style/Theme.Holo.Light.NoActionBar.Fullscreen"
instead of
android:theme="#android:style/Theme.Holo.Light.NoActionBar"
leads to the following problem: if you switch from [NoActionBar Activity] to [ActionBar Activity] ActionBar will JUMP

Related

Material design: Where to place elevation in android styles?

I want to set item elevation in some of my app's styles. Now elevation is only 21 and higher with no support library, so my natural inclination was to just create a styles-v21 xml and place it in there:
<style name="Widget.MyApp.Drawer" parent="ThemeOverlay.AppCompat.Dark.ActionBar">
<item name="android:elevation">4dp</item>
</style>
The problem with this is any changes I make to Widget.MyApp.Drawer in the regular styles.xml file will be overwritten by this completely. What I'd want is for elevation to just be tacked on to the bottom of the list of style changes I made for the v21 version of this style listed in styles.xml.
So I took to creating base styles which the style I use in the views inherits from:
<style name="BaseListElement">
<item name="android:background">#drawable/listitem_background</item>
<item name="android:layout_height">#dimen/list_item_height</item>
</style>
<style name="BaseListElement.ListItem">
</style>
I leave the style blank in styles.xml, and in styles-v21, I add elevation and it works.
However this get's kind of tricky when I want to use some advanced styles:
<style name="BaseListElement">
<item name="android:background">#drawable/listitem_background</item>
<item name="android:layout_height">#dimen/list_item_height</item>
</style>
<style name="BaseListElement.BaseItem">
<item name="android:padding">#dimen/list_item_padding</item>
</style>
<style name="Widget.MyApp.ListItem" parent="#style/BaseListElement.BaseItem">
</style>
<style name="BaseListElement.BaseHeader">
</style>
In this case, BaseItem is just one style that inherits from BaseListElement, styles such as BaseHeader inherit from it as well. This is getting kind of ridiculous as you can see.
Am I overthinking this? The way I see it I have 3 choices here:
1) Continue as is and feel like an idiot
2) On the BaseListElement level, create a child style with some goofy name which is the point at which I apply the elevation, which would then (hopefully) trickle down to all the children. As soon as I have a difference between v21 children of the base however, this wouldn't work.
3) Just throw android:elevation into the styles.xml file (don't use a v21 file) and place an ignore flag on the element. I only have 5.0 devices here, so I can't easily test at the moment if this will cause a crash on older versions.
Any thoughts?
To accomplish something like this you could just create a BaseListElement.BaseItem in both styles.xml and syles-v21.xml the first one without the elevation and the second one with it. Then just extend Widget.MyApp.ListItem from BaseListElement.BaseItem which should get updated in v21 to use the elevation.
styles.xml
<style name="BaseListElement.BaseItem">
</style>
<style name="Widget.MyApp.ListItem" parent="#style/BaseListElement.BaseItem">
</style>
styles-v21.xml
<style name="BaseListElement.BaseItem">
<item name="android:padding">#dimen/list_item_padding</item>
</style>
Method 3 you can safely implement as follows:
<item name="android:elevation" tools:ignore="NewApi">4dp</item>

Theming Android ActionBar: Change TabBar Background

I followed this Guide to style my ActionBar. I use fixed tabs in my app so I want to theme the tabs too.
(Note: I'm using the appcompat theme to ensure some backwards compatibility)
So I used
<style
name="CustomTheme"
parent="#style/Theme.AppCompat.Light" >
<item name="android:actionBarStyle">#style/CustomActionBar</item>
<item name="actionBarStyle">#style/CustomActionBar</item>
<item name="android:actionBarTabStyle">#style/CustomActionBarTabs</item>
<item name="actionBarTabStyle">#style/CustomActionBarTabs</item>
</style>
as my theme.
I set the ActionBar background without problems, but then I tried theming the tabs with:
<style
name="CustomActionBarTabs"
parent="#style/Widget.AppCompat.ActionBar.TabView" >
<item name="android:background">#drawable/customtheme_actionbar_tab_indicator</item>
<item name="background">#drawable/customtheme_actionbar_tab_indicator</item>
</style>
The background points to a StateList where I set different drawables for different contexts, which works kind of as expected. Except it works just for the tabs. Not for the ActionBar.
The separator and the background of the tab bar is not themed.
How can I theme those ? (The grey part)
Theme Creation Guidelines
I wonder if there are any guidelines for creating a theme that looks good ?
(good = similar to default theme, so the app fits into the android ecosystem)
Because If you look closely at the default themes you can see a small line at the bottom of the ActionBar drawable. (The part which is light green in my theme)
There may be other things which you should consider when creating a theme that looks similar to the default themes, so it would be nice to some guideline.
Also: Should the TabBar always be darker than the ActionBar ?
(If so, how much darker?)
How much brighter/darker than the ActionBar color should the image color (like the color of the overflow button in the image) be ?
Thanks in advance,
Uriel
Add this
<style
name="CustomTheme"
parent="#style/Theme.AppCompat.Light" >
.
.
.
<item name="android:actionBarTabBarStyle">#style/TabBar</item>
</style>
And then
<style name="TabBar" parent="#style/Widget.AppCompat.ActionBar.TabBar">
<item name="android:background">/** Whatever color you want, like #ffff00 **/</item>
</style>
Just incase, it may help somebody
This below worked for me
<style name="Theme" parent="Theme.AppCompat.Light.DarkActionBar">
<item name="actionBarTabStyle">#style/Theme.MyActionBarTab</item>
<item name="actionBarTabTextStyle">#style/Theme.MyActionBarTabText</item>
</style>
<style name="Theme.MyActionBarTab" parent="#style/Widget.AppCompat.ActionBar.TabView">
<item name="android:background">#color/gray_mask</item>
</style>
<style name="Theme.MyActionBarTabText" parent="Widget.AppCompat.Light.ActionBar.TabText">
<item name="android:textColor">#color/black</item>
<item name="android:textSize">#dimen/size_28</item>
<item name="android:gravity">center</item>
<item name="textAllCaps">false</item>
</style>

Actionbar Compat change title textColor

I am trying to modify the text color of the title of the ActionBarSupport. I have used ActionBarStyleGenererator to create a theme with the correct colors and it works well.
While using the light theme, I would like to change the color of the heading to white (in the genererator I cannot set the text color(. For a number of reasons I cannot use the dark actionbar theme. I am so close, just have to get the title to white ;-)
What I am doing wrong here?
<style name="ActionBar.Transparent.MyApp" parent="#style/Widget.AppCompat.Light.ActionBar">
<item name="background">#drawable/ab_transparent_myapp</item>
<item name="progressBarStyle">#style/ProgressBar.MyApp</item>
<item name="titleTextStyle">#style/MyApp.TitleTextStyle</item>
</style>
<style name="MyApp.TitleTextStyle" parent="#style/TextAppearance.AppCompat.Widget.Base.ActionBar.Title">
<item name="android:textColor">#ffffff</item>
</style>
The below code worked for me. I hope it will help you tooo.
<style name="AppTheme" parent="AppBaseTheme">
<item name="actionBarStyle">#style/ActionBarCompat</item>
</style>
<style name="ActionBarCompat" parent="#style/Widget.AppCompat.Base.ActionBar">
<item name="titleTextStyle">#style/titleStyle</item>
</style>
<style name="titleStyle" parent="#style/TextAppearance.AppCompat.Widget.Base.ActionBar.Title">
<item name="android:textColor">#android:color/white</item>
</style>
Embarrassing. I was not paying attention to the values-v14/-folder (which overrides the vales/) ActionBarStyleGenererator created. Using the android-prefix on the styles in values-v14 it worked:
<item name="android:titleTextStyle">#style/titleTextStyle</item>
Found at Overflow styling
I've been trying to keep the ActionBar title text color through orientation changes without much luck until I got a clue from the above site. I applied the Spannable to to the title. Here's what i do when setting up my ActionBar:
Spannable actionBarTitle = new SpannableString("Action Bar Title");
actionBarTitle.setSpan(
new ForegroundColorSpan(Color.WHITE),
0,
actionBarTitle.length(),
Spannable.SPAN_EXCLUSIVE_EXCLUSIVE);
mActionBar.setTitle(actionBarTitle);
This needs to be executed on orientation change. I call it from onCreate()...don't know if it works in onConfigurationChange().
#TNR is correct, however you should double check if your layout xml file has not overriden the android:theme attribute with a different style.
This usually happens if you have generated layout files

android:dividerPadding has no effect

This theme works fine, referencing three custom styles for the 3 parts of the ActionBar's tabs.
But the "dividerPadding" has no effect on any of them - running on API 17 devices.
<style name="Theme.AppEmptyTitleBar" parent="android:style/Theme.Holo">
<item name="android:actionBarStyle">#style/AB</item>
<item name="android:actionBarTabStyle">#style/ABT</item>
<item name="android:actionBarTabBarStyle">#style/ABTB</item>
</style>
<style name="AB" parent="android:style/Widget.Holo.ActionBar">
<item name="android:dividerPadding">20dip</item>
</style>
<style name="ABT" parent="android:style/Widget.Holo.Light.ActionBar.TabView">
<item name="android:dividerPadding">20dip</item>
</style>
<style name="ABTB" parent="android:style/Widget.Holo.ActionBar.TabBar">
<item name="android:dividerPadding">20dip</item>
</style>
First of all, the dividerPadding attribute is (as far as I know) only applicable to the *ActionBar.TabBar style.
I've tested your style using a very basic application making use of the native ActionBar and a device providing API 17. I've set the dividerPadding attribute to different values and left the rest of the attributes with default values. Here are the results:
dividerPadding="0dip":
dividerPadding="15dip":
dividerPadding="20dip":
As you can see, divider is gone on the last image. So my first advice would be to check if you see it at all. Other than that, the dividerPadding seems to be working as expected.
My second advice comes from the way Android platform handles style resources placed in different values-* directories. My hunch is that you might be making use of your action bar styles in the default values directory. If you then happen to provide an override of these styles in a values-* directory which is compatible (e.g. values-vX where X <= 17), the styles from values will be ignored. As an example, consider that you've placed these sample styles in the values/styles.xml file:
<resources xmlns:android="http://schemas.android.com/apk/res/android">
<style name="AppTheme" parent="#android:style/Theme.Holo">
<item name="android:actionBarTabBarStyle">#style/ABTB</item>
</style>
<style name="ABTB" parent="#android:style/Widget.Holo.ActionBar.TabBar">
<item name="android:dividerPadding">0dip</item>
</style>
</resources>
If you then place this style definition in values-v17/styles.xml:
<resources xmlns:android="http://schemas.android.com/apk/res/android">
<style name="AppTheme" parent="#android:style/Theme.Holo">
</style>
</resources>
it will override the AppTheme style, effectively "resetting" (technically: ignoring) the whole actionBarTabBarStyle style (including the dividerPadding attribute value). In effect, you won't see any changes made to the ABTB style.
Edit
Yup, I assumed you know that, sorry :( The dividerPadding value applies only to:
Top and bottom of divider when the TabWidget (it's the container of tab labels) draws tabs horizontally.
Left and right sides of divider when the TabWidget draws tabs vertically.
Which is exactly what you see in the screenshots. As far as I know, you have to set divider to a drawable which will force additional padding. I believe the layer drawable will be great for that purpose because you can set padding explicitly for every layer.

ActionBar Sherlock - Backgroundimage in Actionbar

I would love to set a Backgroundimage to the ActionBar which I imported with the "ActionBar Sherlock" library. However I can't find any link on the internet on how to distinctively set an BackgroundImage with XML.
Does anybody here have a hint which he could give me :)?
You create a style for your actionbar, it has to inherit Theme.Sherlock or Theme.Sherlock.Light.
Then link to your image in the attribute abBackground.
Assuming you have an image called myBackgroundImage in res/drawable your style xml would be:
<style name="Actionbar" parent="Theme.Sherlock">
<item name="abBackground">#drawable/myBackgroundImage</item>
</style>
You can find more attributes for the actionbar here: ActionBarSherlock - Theming
More on styles is found here: Styles and Themes | Android Developers
In your style.xml file add a custom style like this:
<style name="MyActionBarStyle" parent="Widget.Sherlock.ActionBar.TabBar">
<item name="android:background">#drawable/actionbar_tab_bg</item>
</style>
and add this style to your app theme with this to lines, the first for the Android <3.0 and the second for the >3.0
<style name="ReservasAppTheme" parent="#style/Theme.Sherlock.Light">
<item name="actionBarTabStyle">#style/MyActionBarStyle</item>
<item name="android:actionBarTabStyle">#style/MyActionBarStyle</item>
</style>
You should add this style to the application tag in manifest
you might want to look at : http://actionbarsherlock.com/theming.html

Categories

Resources