0

When I try to do a TabHost with an icon and a text, Only the text is visible, if I left the text in blank it is possible to see the icon. I want to see both on screen. I tried to do it with a Layout and an Inflater without success. Could you please check what is wrong in my code?

 TabHost tabHost = (TabHost)findViewById(R.id.tabHost);


    Intent intent = new Intent(this,activity1.class);
    TabHost.TabSpec tabSpec1 = tabHost.newTabSpec("SMS");
    View tabIndicator = LayoutInflater.from(this).inflate(R.layout.tab_layout, tabHost.getTabWidget(), false);
    TextView title1 = (TextView) tabIndicator.findViewById(R.id.my_text);
    title1.setText("SMS");
    ImageView icon1 = (ImageView) tabIndicator.findViewById(R.id.my_image);
    icon1.setImageResource(R.drawable.ajout);
    tabSpec1.setIndicator(tabIndicator);
    tabSpec1.setContent(intent);
    tabHost.addTab(tabSpec1);

    Intent intent1 = new Intent(this, activity1.class);
    TabHost.TabSpec spec2 = tabHost.newTabSpec("MMS");
    View tabIndicator1 = LayoutInflater.from(this).inflate(R.layout.tab_layout, tabHost.getTabWidget(), false);
    TextView title2 = (TextView) tabIndicator.findViewById(R.id.my_text);
    title2.setText("MMS");
    ImageView icon2 = (ImageView) tabIndicator.findViewById(R.id.my_image);
    icon2.setImageResource(R.drawable.suppression);
    spec2.setIndicator(tabIndicator1);
    spec2.setContent(intent1);
    tabHost.addTab(spec2);
Francis Ngueukam
  • 994
  • 1
  • 10
  • 28
  • 1
    The use of activities-as-tabs has been deprecated for **over four years**. Please use a more modern tab solution, such as `ViewPager` with a tabbed indicator, or `FragmentTabHost`. – CommonsWare May 28 '15 at 21:27
  • Thanks, i found one of the best way to do it : [Click here](http://stackoverflow.com/questions/17687717/tutorial-to-implement-the-use-of-tabhost-in-android-2-2-viewpager-and-fragment) – Francis Ngueukam May 29 '15 at 08:06

0 Answers0