将标签添加到TabHost for Android的正确方法是什么?

时间:2012-07-07 05:07:41

标签: android eclipse android-tabhost tabwidget

我是Android开发的新手。

我已经在我的Android应用程序中添加了一个TabHost,并且可以更改我正常使用的三个选项卡的文本。我可以点击它们来显示不同的视图等。

但是我在何处以及如何在特定标签中添加图标?不是以编程方式更改它,而是实际将其添加到布局设计中?在XML中还是以某种方式使用设计器?

1 个答案:

答案 0 :(得分:0)

执行以下操作:

    TabHost tabHost=getTabHost();
    TabHost.TabSpec spec;
    TabHost.TabSpec spec=tabHost.newTabSpec("hello").setIndicator("hello",getResources().getDrawable(R.drawable.ic_launcher)).setContent(intent);
    tabHost.addTab(spec);

这是将图标设置为特定标签的最简单方法。