1

I have implemented tabs using FragmentTabHost in support package, but the drawable icon is not shown?

How to show the drawable icon with FragmentTabHost?

mTabs = (FragmentTabHost)findViewById(android.R.id.tabhost);
mTabs.setup(this, getSupportFragmentManager(), R.id.realtabcontent);

mTabs.addTab(mTabs.newTabSpec("chapter").setIndicator("Chapter",getResources().
getDrawable(R.drawable.chapter1)), ContentFragment.class, null);

mTabs.addTab(mTabs.newTabSpec("section").setIndicator("section",getResources().
    getDrawable(R.drawable.favourite1)), SectionFragment.class, null);
mTabs.addTab(mTabs.newTabSpec("video").setIndicator("Video",getResources().
    getDrawable(R.drawable.video1)),VideoFragment.class, null);
mTabs.addTab(mTabs.newTabSpec("about").setIndicator("About",getResources().
    getDrawable(R.drawable.about1)),AboutFragment.class, null);
lopez.mikhael
  • 9,943
  • 19
  • 67
  • 110
Raneez Ahmed
  • 3,808
  • 3
  • 35
  • 58
  • Do you use ICS for testing? – Oli May 23 '13 at 18:12
  • 2
    In ICS you should use `setIndicator(View view)` Please check [This](http://stackoverflow.com/questions/10745092/icon-in-tab-is-not-showing-up/11379708#11379708) I had the same problem – Oli May 23 '13 at 18:16
  • it works but the selection of the menu disappears. How can i bring the selection back? – Duna Aug 05 '13 at 18:45

1 Answers1

5

I had the same problem. Apparently, setIndicator(label, icon) does not work correctly. As a workaround, I used setIndicator(view) and created a simple custom view in tab_indicator.xml. For each tab, set the title and icon.

Appulus
  • 18,630
  • 11
  • 38
  • 46
  • 3
    it works but the selection of the menu disappears. How can i bring the selection back? – Duna Jul 29 '13 at 07:17
  • 1
    @Lunatikul u were able to get that selection back? – Mohit Oct 27 '14 at 07:41
  • I am following the same as you did, where am i wrong see my question http://stackoverflow.com/questions/28047245/add-selector-image-to-fragmenttabhost – Zar E Ahmer Jan 20 '15 at 14:10