0

This is the code I am using to set the divider between by tabs in the tab host.

mTabHost.getTabWidget().setDividerDrawable(R.drawable.tabdivider);

But it does not show up in the emulator. Searching around on SO led me to many posts regarding this but I have not been able to come to a perfect solution to this.

Any help/suggestion in this regard will be really helpful.

Swayam
  • 16,294
  • 14
  • 64
  • 102

1 Answers1

2

TabHost is deprecated in android api level 11 onwards.

Try using ActionBar.

For more details, see this.

UPDATE:

Please see this, for using setDrawable in ICS.

UPDATE: If you want to make use of tabs on all android versions, you can use the following code:

if (android.os.Build.VERSION.SDK_INT >= 11) {

// setup action bar for tabs
    ActionBar actionBar = getActionBar();
    actionBar.setNavigationMode(ActionBar.NAVIGATION_MODE_TABS);
    actionBar.setDisplayShowTitleEnabled(false);

    Tab tab = actionBar.newTab()
            .setText(R.string.artist)
            .setTabListener(new TabListener<ArtistFragment>(
                    this, "artist", ArtistFragment.class));
    actionBar.addTab(tab);

    tab = actionBar.newTab()
        .setText(R.string.album)
        .setTabListener(new TabListener<AlbumFragment>(
                this, "album", AlbumFragment.class));
    actionBar.addTab(tab);
} else {

// put your TabHost code here...

}

This should be placed in your onCreate() method.

Community
  • 1
  • 1
Shrikant Ballal
  • 7,067
  • 7
  • 41
  • 61
  • Is there no way to achieve this using TabHost ? – Swayam Jun 27 '12 at 10:38
  • 1
    TabHost works perfectly on android 4, but it is suggested that, you should use ActionBar, and seriously they are very easy to use. I can explain you that. And if you want to use only TabHost then, you have provided not enough info about the problem. Exactly what problems are you facing? – Shrikant Ballal Jun 27 '12 at 10:43
  • The problem is that the divider does not show in the device even though I have used setDividerDrawable() as given in the question. – Swayam Jun 27 '12 at 10:46
  • I have updated the ActionBar link. If you want, please go through it. – Shrikant Ballal Jun 27 '12 at 10:46
  • I will still suggest you to use ActionBar. Because, using TabBar in ICS, is not good practice. If you have any specific requirement then its ok. – Shrikant Ballal Jun 27 '12 at 10:53
  • Where you see TabHost is deprecated? http://developer.android.com/intl/es/reference/android/widget/TabHost.html – PaNaVTEC Oct 19 '12 at 06:48
  • Actually TabActivity is deprecated, http://developer.android.com/reference/android/app/TabActivity.html – Shrikant Ballal Oct 19 '12 at 06:55