Android 选项卡下的条带未绘制

Android 选项卡下的条带未绘制,android,tabs,strip,Android,Tabs,Strip,在我的活动中我这样做是为了设置TabHost: //... mTabHost = (TabHost) findViewById(android.R.id.tabhost); mTabHost.getTabWidget().setDividerDrawable(R.drawable.my_divider_tab); mTabHost.getTabWidget().setStripEnabled(true); mTabHost

在我的活动中我这样做是为了设置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>
在这里:

所以,当我们为选项卡使用自定义视图时(就像我正在做的),条带会自动禁用。。。
如何启用它?

我找到的解决此问题的唯一解决方案是:

//...
<TabWidget
        android:id="@android:id/tabs"
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"/>

    <FrameLayout
        android:id="@android:id/tabcontent" 
        android:layout_width="fill_parent"
        android:layout_height="fill_parent" >


        <View
            android:id="@+id/my_strip_tab"
            android:layout_width="fill_parent"
            android:layout_height="3dp" 
            android:background="@drawable/my_strip_tab"/>

//...

    </FrameLayout>
/。。。
//...
my\u strip\u 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="#67E667"/>

</shape>

你唯一要做的就是移动这段代码

    mTabHost.getTabWidget().setStripEnabled(true);
    mTabHost.getTabWidget().setLeftStripDrawable(R.drawable.my_strip_tab);
    mTabHost.getTabWidget().setRightStripDrawable(R.drawable.my_strip_tab);
在完成所有设置选项卡()之后


如果您查看Google文档,其原因是当您对选项卡指示器使用自定义视图时,会自动调用setTripEnabled(false)。您只需在设置所有自定义视图或选项卡指示器后重新启用它。

我也遇到了同样的问题。我解决了这个问题:1)将我的设置行移到设置选项卡的下方;2)我的绘图表没有指定大小。感谢amp和@brian wang,现在效果很好
    mTabHost.getTabWidget().setStripEnabled(true);
    mTabHost.getTabWidget().setLeftStripDrawable(R.drawable.my_strip_tab);
    mTabHost.getTabWidget().setRightStripDrawable(R.drawable.my_strip_tab);