Ken*_*and 4 android android-tabhost
我有一个在TabHost中有3个标签的Android应用程序(文本标签,没有图像).我像这样设置标签:
intent = new Intent().setClass(this, AnnouncementsActivity.class);
spec = tabHost.newTabSpec("news").setIndicator("News").setContent(intent);
tabHost.addTab(spec);
Run Code Online (Sandbox Code Playgroud)
我启动了一个后台线程来从我的服务器获取通知,我想更新选项卡上的文本标签,告诉用户有多少新公告.例如,我想将Tab上的文本更改为"News(3)".如何访问和更改选项卡上的文本标签?
欢迎任何建议!
你可以这样做
TabHost tabHost = getTabHost();
TextView tv = (TextView) tabHost.getTabWidget().getChildAt(0).findViewById(android.R.id.title);
tv.setText("New Tab Text");
Run Code Online (Sandbox Code Playgroud)
哪里android.R.id.title是系统生成的,只是改变ChildIndex和文本根据您的需要
| 归档时间: |
|
| 查看次数: |
10240 次 |
| 最近记录: |