FragmentTabHost更改选项卡名称

时间:2013-07-23 15:38:31

标签: android android-fragments fragment-tab-host

用addTab(mTabHost.newTabSpec(....))设置我的FragmentTabHost后,我不知道如何获取对TabSpec的引用。

我需要的是更改我最初使用mTabHost.newTabSpec方法设置的选项卡的名称(tabSpec.setIndicator(“new name”))。

谢谢!

2 个答案:

答案 0 :(得分:0)

我自己找到答案。只需在fragmentTabHost对象上调用此方法即可:

((TextView((RelativeLayout)getTabWidget().getChildAt(tabIndex)).getChildAt(textIndex)).setText("NewTabText");

答案 1 :(得分:0)

我认为这是完成任务的更直接方式:

((TextView) mTabHost.getCurrentTabView().findViewById(android.R.id.title))
.setText(yourTitle);

无论谁写这个都应该定义一个setTabText(int position, String text)方法,否则谁会知道他们有一个文本视图ID android.R.id.title?或者,如果他们已经有,请赐教。