Tabs using action bar vs TabHost

2.7k Views Asked by At

I want to create a simple application where I can

  1. Put tabs on the bottom of the screen
  2. Edit the physical look/appearance of the tabs

On one hand, it seems that the most modern way to do this, for now, is using Action Bar:

actionBar.setNavigationMode(ActionBar.NAVIGATION_MODE_TABS);

But it seems to me that it is not possible to do both using the tabs from the action bar.

To perform the two things I want, do I have to use TabHost, with fragments (the older way) or can I use the action bar tabs with fragments?

1

There are 1 best solutions below

5
On

I use ActionBar tabs in my application, and I customize their look via android stles/themes.

In the theme:

<style name="AppBaseTheme.Light" parent="android:Theme.Holo.Light.DarkActionBar">
    ...
    <item name="android:actionBarTabStyle">@style/MyTabView</item>
    ...
</style>

Then I define a style:

<style parent="@android:style/Widget.Holo.ActionBar.TabView" name="MyTabView">
    <item name="android:background">@drawable/tab_bg</item>
</style>

Your 'drawable' can be a 9-patch, layer-list, selector, image, etc.