在我的活动中,我这样做是为了设置 TabHost:
//...
mTabHost = (TabHost) findViewById(android.R.id.tabhost);
mTabHost.getTabWidget().setDividerDrawable(R.drawable.my_divider_tab);
mTabHost.getTabWidget().setStripEnabled(true);
mTabHost.getTabWidget().setLeftStripDrawable(R.drawable.my_strip_tab);
mTabHost.getTabWidget().setRightStripDrawable(R.drawable.my_strip_tab);
setupTab(new TextView(this), getString(R.string.device_text_tab));
setupTab(new TextView(this), getString(R.string.sensor_text_tab));
setupTab(new TextView(this), getString(R.string.actuator_text_tab));
//...
private void setupTab(final View view, final String tag) {
View tabview = createTabView(mTabHost.getContext(), tag);
TabSpec setContent = mTabHost.newTabSpec(tag).setIndicator(tabview).setContent(new TabContentFactory() {
public View createTabContent(String tag) {return view;}
});
mTabHost.addTab(setContent);
}
private static View createTabView(final Context context, final String text) {
View view = LayoutInflater.from(context).inflate(R.layout.state_tabwidget, null);
TextView tv = (TextView) view.findViewById(R.id.tabsText);
tv.setText(text);
return view;
}
my_strip_tab.xml只是一个矩形:
<?xml version="1.0" encoding="utf-8"?>
<shape
xmlns:android="http://schemas.android.com/apk/res/android"
android:shape="rectangle">
<solid
android:color="#FFFFFF"/>
<size
android:width="0dp"
android:height="2dp"/>
</shape>
绘制垂直分隔线。但是选项卡下的条带没有显示...
可能是什么问题呢?的大小my_strip_tab
?
我刚刚发现:
/**
* Controls whether the bottom strips on the tab indicators are drawn or
* not. The default is to draw them. If the user specifies a custom
* view for the tab indicators, then the TabHost class calls this method
* to disable drawing of the bottom strips.
* @param stripEnabled true if the bottom strips should be drawn.
*/
因此,当我们对选项卡使用自定义视图时(就像我正在做的那样),条似乎会自动禁用......我该如何启用它?