Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Custom style for stacked action bar?

I want to have separate backgrounds for stacked and non-stacked tab bars.

This should explain it:

enter image description here

So the way I have it is:

For tablets, use dark background tabs. For everything else, use light background.

This covers most use cases, but I'd like to make it not look bad in phone-landscape.

Any way I can do this? A style modifier I missed, maybe?

like image 375
Steven Schoen Avatar asked Sep 19 '12 05:09

Steven Schoen


1 Answers

You can change the tab background depending on stacked/non-stacked ActionBar by setting the light background drawable only for android:backgroundStacked in your theme.

But then you run into the problem that you can't define the tab text color based on stacked/non-stacked layout. That means, the result is either light text on light background or dark text on dark background.

This is already a registered issue: http://code.google.com/p/android/issues/detail?id=26557, so your options now are either waiting or using one of these workarounds:

  • Approach based on the available width of the screen: Android change action bar tab's selector color when split or stacked
  • Approach based on the height of your ActionBar: Find out if ActionBar is stacked
  • Not using actionBar.setNavigationMode(ActionBar.NAVIGATION_MODE_TABS) but sticking with old-school TabHost or other navigation approaches such as ViewPagerIndicator (also supporting tabs)

P.S. I'm also facing this issue as I have a dark ActionBar with light tabs in my app. Still haven't found the perfect solution.

A little off-topic: If you haven't already, use the Action Bar Style Generator to deal with colors and drawables easier. Again, you'll find no satisfactory configuration for a dark action bar with a light stacked tab bar.

like image 73
saschoar Avatar answered Sep 19 '22 13:09

saschoar