Android 更改tabhost样式

Android 更改tabhost样式,android,android-tabhost,Android,Android Tabhost,我想将tabhost的默认蓝色更改为红色 <style name="AppTheme" parent="android:Theme.Light.NoTitleBar"> <item name="android:tabWidgetStyle">@drawable/tab_indicator_holo</item> </style> @可拉拔/标签指示器 tab_indicator_holo.xml <

我想将tabhost的默认蓝色更改为红色

<style name="AppTheme" parent="android:Theme.Light.NoTitleBar">
          <item name="android:tabWidgetStyle">@drawable/tab_indicator_holo</item>
          </style>

@可拉拔/标签指示器
tab_indicator_holo.xml

<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>

但是选项卡样式不应用于tabhost。默认的蓝色不会更改为红色

我明白了


请提供任何想法或建议。

您可能已经找到了答案,但对于那些可能面临相同问题的人,以下是我所做的

  • 转到并将tabwedget设置为“是”,然后选择首选颜色

  • 下载zip文件,复制到我的项目中

  • 添加到tabadapter,使用通过膨胀tab_指示器_holo创建的视图


  • 你可能已经找到了答案,但对于那些可能面临同样问题的人来说,以下是我所做的

  • 转到并将tabwedget设置为“是”,然后选择首选颜色

  • 下载zip文件,复制到我的项目中

  • 添加到tabadapter,使用通过膨胀tab_指示器_holo创建的视图


  • android:tabWidgetStyle
    应该指向扩展样式的
    Widget.TabWidget
    (这反过来会覆盖它的一个选项卡条属性,以指向您拥有的
    tab_指示器\u holo.xml
    可绘图)。
    android:tabWidgetStyle
    应该指向扩展样式的
    Widget.TabWidget
    (这反过来会覆盖它的一个tab strip属性,以指向您拥有的
    tab\u indicator\u holo.xml
    drawable)。谢谢!这正是我需要的。太棒了!NyanLH,你能完成你的代码示例吗?要将其添加到哪个函数?inflater,MTABAdapter来自哪里?谢谢!这正是我需要的。太棒了!NyanLH,你能完成你的代码示例吗?inflater,MTABAdapter来自哪里从…起
        View mIndicator = inflater.inflate(R.layout.tab_indicator_holo, mTabHost.getTabWidget(), false);
        TextView title1 = (TextView) mIndicator.findViewById(android.R.id.title);
    
        title1.setText("TAB1");
    
        mTabsAdapter.addTab(mTabHost.newTabSpec("TAB1").setIndicator( mIndicator), FRAGMENT1.class, null);
    
        View mIndicator2 = inflater.inflate(R.layout.tab_indicator_holo,      mTabHost.getTabWidget(), false);
        TextView title2 = (TextView) mIndicator2.findViewById(android.R.id.title);
    
        title2.setText("TAB2");
        mTabsAdapter.addTab(mTabHost.newTabSpec("TAB2").setIndicator(mIndicator2), FRAGMENT2.class, null);