我TabActivity 与它是由几个不同的活动,这样的底部标签:如何更改标签的标题TabActivity
public class HomeScreen extends TabActivity {
private TabHost mTabHost;
@Override
public void onCreate(Bundle icicle) {
super.onCreate(icicle);
try{
setContentView(R.layout.hometabs);
Resources res = getResources(); // Resource object to get Drawables
mTabHost = getTabHost(); // The activity TabHost
TabHost.TabSpec spec; // Reusable TabSpec for each tab
Intent intent; // Reusable Intent for each tab
String strName;
// Create an Intent to launch an Activity for the tab (to be reused)
strName=Central.Res.getString(R.string.tab_Books);
intent = new Intent().setClass(this, BookList.class);
spec = mTabHost.newTabSpec(strName).setIndicator("",
res.getDrawable(R.drawable.ic_menu_database))
.setContent(intent);
mTabHost.addTab(spec);
// Create an Intent to launch an Activity for the tab (to be reused)
strName=Central.Res.getString(R.string.tab_Questions);
intent = new Intent().setClass(this, QuestionsList.class);
intent.putExtra("NoteType", UserDataSQLHelper.NOTE_TYPE_QUEST);
spec = mTabHost.newTabSpec(strName).setIndicator("",
res.getDrawable(R.drawable.ic_menu_dialog))
.setContent(intent);
mTabHost.addTab(spec);
我的问题是,我对每一个相同的窗口标题标签。此窗口标题设置为应用程序名称。
我需要能够将此标题更改为选项卡的名称。
我试图通过调用setTitle(“MyTitle”);在相应的活动中的onCreate(),并通过覆盖TabActivity onChildTitleChanged:
public void onChildTitleChanged(Activity childActivity, CharSequence title)
{
View tabView = mTabHost.getCurrentTabView();
int idTitle = android.R.id.title;
TextView tvTitle = (TextView) tabView.findViewById(idTitle);
tvTitle.setText(title);
}
但结果我得到的是不是我所需要的 - 它的标签图标下设置文本标签。
你能帮我吗?
谢谢,已经试过了。相同 - 更改标签图标下方的文字。 – Ivan
嗨,现在编辑我的答案。试试我上面发布的新代码。 –
谢谢!有用。唯一的事情是,第一次打开的标签仍然会得到错误的标题,用户必须切换标签才能重置它。 – Ivan