对于更高版本的android(5.1),这对我有用:
请注意,此示例仅更改第一个选项卡的文本。调整任意选项卡不会太难。
FragmentTabHost tabHost = (FragmentTabHost)view.findViewById(android.R.id.tabhost);
AppCompatTextView tv = null;
RelativeLayout parentLayout = (RelativeLayout)tabHost.getTabWidget().getChildAt(0);
for (int i = 0; i < parentLayout.getChildCount(); i++) {
View tempView = parentLayout.getChildAt(i);
if (tempView instanceof AppCompatTextView) {
tv = (AppCompatTextView)tempView;
}
}
if (tv != null) {
tv.setText("Your updated text goes here");
}
我所做的只是通过调试器运行它并找出层次结构。我无法让 android.R.id.title 工作,因为文本视图现在由不同的 id 引用。无论如何,它现在也是 AppCompatTextView 而不是普通的旧 TextView。
同样,这不是最佳的,但对于较新版本的 android 可以获得所需的结果。
希望这可以帮助!