我知道 API 3 不允许为选项卡设置 View ,但我仍然需要修改显示为指示器的 TextView。我还想更改选项卡的 Drawable,但我看不到没有 1.6 API 4 允许的自定义选项卡 View 的方法。
使用下面这个通用示例,有没有办法检索 TextView 并修改其属性或更改可绘制对象?
TabHost tabHost = getTabHost();
TabHost.TabSpec spec;
spec = tabHost.newTabSpec("nearby")
.setIndicator("Nearby Activity")
.setContent(R.id.nearby_list);
tabHost.addTab(spec);
spec = tabHost.newTabSpec("friends")
.setIndicator("Friends & Favorites")
.setContent(R.id.friends_list);
tabHost.addTab(spec);
tabHost.setCurrentTabByTag("nearby");
感谢您的帮助。
最佳答案
改变图标:
.setIndicator("Friends & Favorites",getResources().getDrawable(R.drawable.myTabIcon))
更改 TabBackground Drawable::
tabHost.getTabWidget().getChildAt( index of tab ).setBackgroundResource(R.drawable.mytab_Newbackground);
要检索 Textview,请检查 Francesco 的示例
ViewGroup v = (ViewGroup) tabHost.getTabWidget().getChildAt( index of tab );
TextView tv = (TextView)v.getChildAt(1);
Log.d("Tab's text = ",tv.getText().toString());
关于java - 在 SDK 1.5、API 3 中自定义 TabWidget,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/2981069/