Android Can';t更改碎片选项卡主机选项卡的指示器颜色

Android Can';t更改碎片选项卡主机选项卡的指示器颜色,android,tabs,styles,fragment-tab-host,Android,Tabs,Styles,Fragment Tab Host,我想在我的应用程序中实现一个自定义FragmentTabHost。关于这个主题的文档是有限的,我无法让它与我的自定义指示器绘图(绿色)一起工作,它们不会显示在选项卡按钮下 我只得到默认的蓝色指示器。有什么不对劲? 谢谢 tab_text_selector.xml <!-- AOSP copyright notice can be found at the above link --> <selector xmlns:android="http://schemas.android

我想在我的应用程序中实现一个自定义FragmentTabHost。关于这个主题的文档是有限的,我无法让它与我的自定义指示器绘图(绿色)一起工作,它们不会显示在选项卡按钮下

我只得到默认的蓝色指示器。有什么不对劲? 谢谢

tab_text_selector.xml

<!-- AOSP copyright notice can be found at the above link -->
<selector xmlns:android="http://schemas.android.com/apk/res/android">
    <!-- Non focused states -->
    <item android:state_focused="false" android:state_selected="false" android:state_pressed="false" android:drawable="@drawable/tab_unselected_holo" />
    <item android:state_focused="false" android:state_selected="true"  android:state_pressed="false" android:drawable="@drawable/tab_selected_holo" />

    <!-- Focused states -->
    <item android:state_focused="true" android:state_selected="false" android:state_pressed="false" android:drawable="@drawable/tab_unselected_focused_holo" />
    <item android:state_focused="true" android:state_selected="true"  android:state_pressed="false" android:drawable="@drawable/tab_selected_focused_holo" />

    <!-- Pressed -->
    <!--    Non focused states -->
    <item android:state_focused="false" android:state_selected="false" android:state_pressed="true" android:drawable="@drawable/tab_unselected_pressed_holo" />
    <item android:state_focused="false" android:state_selected="true"  android:state_pressed="true" android:drawable="@drawable/tab_selected_pressed_holo" />

    <!--    Focused states -->
    <item android:state_focused="true" android:state_selected="false" android:state_pressed="true" android:drawable="@drawable/tab_unselected_pressed_holo" />
    <item android:state_focused="true" android:state_selected="true"  android:state_pressed="true" android:drawable="@drawable/tab_selected_pressed_holo" />
</selector>

我遇到了这样的问题,我用下面的代码语句解决了它:

mTabHost.getTabWidget().getChildAt(mTabHost.getCurrentTab()).setBackgroundResource(R.drawable.tab_selected);
祝你好运

mTabHost.getTabWidget().getChildAt(mTabHost.getCurrentTab()).setBackgroundResource(R.drawable.tab_selected);