在片段活动中设置Android选项卡的背景色

在片段活动中设置Android选项卡的背景色,android,android-fragments,Android,Android Fragments,我尝试将现有代码从TabActivity迁移到FragmentActivity,因为TabActivity现在已不推荐使用 在此之前,我使用以下代码更改每个选项卡的背景色: TabWidget widget = tabHost.getTabWidget(); for(int i = 0; i < widget.getChildCount(); i++) { View v = widget.getChildAt(i); //

我尝试将现有代码从TabActivity迁移到FragmentActivity,因为TabActivity现在已不推荐使用

在此之前,我使用以下代码更改每个选项卡的背景色:

TabWidget widget = tabHost.getTabWidget();
        for(int i = 0; i < widget.getChildCount(); i++) {
            View v = widget.getChildAt(i);

            // Look for the title view to ensure this is an indicator and not a divider.
            TextView tv = (TextView)v.findViewById(android.R.id.title);
            tv.setTextColor(Color.parseColor("#E64260"));
            tv.setTextSize(15);
            tv.setTypeface(robotolight);

            v.setBackgroundResource(R.drawable.tab_selector);
        }
TabWidget widget=tabHost.getTabWidget();
对于(int i=0;i
tab_selector.xml:

<selector xmlns:android="http://schemas.android.com/apk/res/android">

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

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

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

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

我不知道如何使这段代码适应片段活动。你能帮我吗

更新:

<?xml version="1.0" encoding="utf-8"?>
<!-- File created by the Android Action Bar Style Generator

     Copyright (C) 2011 The Android Open Source Project
     Copyright (C) 2012 readyState Software Ltd

     Licensed under the Apache License, Version 2.0 (the "License");
     you may not use this file except in compliance with the License.
     You may obtain a copy of the License at

          http://www.apache.org/licenses/LICENSE-2.0

     Unless required by applicable law or agreed to in writing, software
     distributed under the License is distributed on an "AS IS" BASIS,
     WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
     See the License for the specific language governing permissions and
     limitations under the License.
-->

<resources>

    <style name="Theme.Detail_bar_style" parent="@android:style/Theme.Holo.Light">
        <item name="android:actionBarItemBackground">@drawable/selectable_background_detail_bar_style</item>
        <item name="android:popupMenuStyle">@style/PopupMenu.Detail_bar_style</item>
        <item name="android:dropDownListViewStyle">@style/DropDownListView.Detail_bar_style</item>
        <item name="android:actionBarTabStyle">@style/ActionBarTabStyle.Detail_bar_style</item>
        <item name="android:actionDropDownStyle">@style/DropDownNav.Detail_bar_style</item>
        <item name="android:actionBarStyle">@style/ActionBar.Solid.Detail_bar_style</item>
        <item name="android:actionModeBackground">@drawable/cab_background_top_detail_bar_style</item>
        <item name="android:actionModeSplitBackground">@drawable/cab_background_bottom_detail_bar_style</item>
        <item name="android:actionModeCloseButtonStyle">@style/ActionButton.CloseMode.Detail_bar_style</item>


    </style>

    <style name="ActionBar.Solid.Detail_bar_style" parent="@android:style/Widget.Holo.Light.ActionBar.Solid">
        <item name="android:background">@drawable/ab_background_textured_detail_bar_style</item>
        <item name="android:backgroundStacked">@drawable/ab_stacked_solid_detail_bar_style</item>
        <item name="android:backgroundSplit">@drawable/ab_background_textured_detail_bar_style</item>
        <item name="android:progressBarStyle">@style/ProgressBar.Detail_bar_style</item>
    </style>

    <style name="ActionBar.Transparent.Detail_bar_style" parent="@android:style/Widget.Holo.Light.ActionBar">
        <item name="android:background">@drawable/ab_transparent_detail_bar_style</item>
        <item name="android:progressBarStyle">@style/ProgressBar.Detail_bar_style</item>
    </style>

    <style name="PopupMenu.Detail_bar_style" parent="@android:style/Widget.Holo.Light.ListPopupWindow">
        <item name="android:popupBackground">@drawable/menu_dropdown_panel_detail_bar_style</item>  
    </style>

    <style name="DropDownListView.Detail_bar_style" parent="@android:style/Widget.Holo.Light.ListView.DropDown">
        <item name="android:listSelector">@drawable/selectable_background_detail_bar_style</item>
    </style>

    <style name="ActionBarTabStyle.Detail_bar_style" parent="@android:style/Widget.Holo.Light.ActionBar.TabView">
        <item name="android:background">@drawable/tab_indicator_ab_detail_bar_style</item>
    </style>

    <style name="DropDownNav.Detail_bar_style" parent="@android:style/Widget.Holo.Light.Spinner">
        <item name="android:background">@drawable/spinner_background_ab_detail_bar_style</item>
        <item name="android:popupBackground">@drawable/menu_dropdown_panel_detail_bar_style</item>
        <item name="android:dropDownSelector">@drawable/selectable_background_detail_bar_style</item>
    </style>

    <style name="ProgressBar.Detail_bar_style" parent="@android:style/Widget.Holo.Light.ProgressBar.Horizontal">
        <item name="android:progressDrawable">@drawable/progress_horizontal_detail_bar_style</item>
    </style>

    <style name="ActionButton.CloseMode.Detail_bar_style" parent="@android:style/Widget.Holo.Light.ActionButton.CloseMode">
        <item name="android:background">@drawable/btn_cab_done_detail_bar_style</item>
    </style>

    <!-- this style is only referenced in a Light.DarkActionBar based theme -->
    <style name="Theme.Detail_bar_style.Widget" parent="@android:style/Theme.Holo">
        <item name="android:popupMenuStyle">@style/PopupMenu.Detail_bar_style</item>
        <item name="android:dropDownListViewStyle">@style/DropDownListView.Detail_bar_style</item>
    </style>

</resources>

@可绘制/可选择的\u背景\u细节\u栏\u样式
@样式/PopupMenu.Detail\u bar\u样式
@样式/下拉列表视图.Detail\u bar\u样式
@样式/动作BARTABSTYLE.DETAILE\U bar\U样式
@样式/下拉导航.详细信息\条形图\样式
@样式/ActionBar.Solid.Detail\u bar\u样式
@可拉伸/驾驶室\背景\顶部\细节\酒吧\风格
@可拉伸/驾驶室\背景\底部\细节\酒吧\风格
@样式/ActionButton.CloseMode.Detail\u栏\u样式
@可绘制/ab_背景_纹理_细节_条形_风格
@可拉伸/ab_堆叠_实心_详图_条形_样式
@可绘制/ab_背景_纹理_细节_条形_风格
@样式/ProgressBar.Detail\u bar\u样式
@可绘制/ab_透明_细节_条形_样式
@样式/ProgressBar.Detail\u bar\u样式
@可绘图/菜单\下拉菜单\面板\详图\栏\样式
@可绘制/可选择的\u背景\u细节\u栏\u样式
@可绘制/制表符\指示器\制表符\详图\条形图\样式
@可绘制/微调器\u背景\u ab\u细节\u条形\u样式
@可绘图/菜单\下拉菜单\面板\详图\栏\样式
@可绘制/可选择的\u背景\u细节\u栏\u样式
@可绘制/进度\水平\详图\条形\样式
@可拉伸/btn\u驾驶室\u完成\u细节\u酒吧\u风格
@样式/PopupMenu.Detail\u bar\u样式
@样式/下拉列表视图.Detail\u bar\u样式

您可以通过
style.xml

<?xml version="1.0" encoding="utf-8"?>
<resources>
  <style name="MyTheme" parent="@android:style/Theme.Holo.Light">
    <item name="android:actionBarStyle">@style/MyTheme.ActionBarStyle</item>
  </style>

  <style name="MyTheme.ActionBarStyle"parent="@android:style/Widget.Holo.Light.ActionBar">
    <item name="android:titleTextStyle">@style/MyTheme.ActionBar.TitleTextStyle</item>
  </style>

  <style name="MyTheme.ActionBar.TitleTextStyle" parent="@android:style/TextAppearance.Holo.Widget.ActionBar.Title">
    <item name="android:textColor">@color/red</item>
  </style>
</resources>

@style/MyTheme.ActionBarStyle
@style/MyTheme.ActionBar.TitleTextStyle
@颜色/红色
如果您正在使用ActionBarSherlock,请尝试使用此


我是为了我自己的目的才提到的。想和你分享一下。

好的,谢谢。之后,我如何为我的FragmentActivity设置此文件?$您需要在该特定活动的android清单文件中包含主题。您知道我可以在哪里更改操作栏文本的颜色吗?您可以通过Java代码或通过styles.xml(已在我的回答中说明)来更改该颜色.我已经用我用你的链接生成的Complete样式文件更新了我的帖子。没有文本颜色线。我必须在哪里加这一行?