0

I try to migrate my existing code from TabActivity to FragmentActivity because TabActivity is now deprecated.

Until here, i used this code to change the background color of each tab :

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);
        }

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>

I don't know how to adapt this code for Fragment Activity. Could you help me ?

UPDATE :

<?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>
wawanopoulos
  • 9,614
  • 31
  • 111
  • 166

1 Answers1

1

You can achieve your aim through styles.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>

And if you are using ActionBarSherlock, try using this ActionBarStyle Generator

I referred this link for my own purpose. Thought of sharing the same with you.

Community
  • 1
  • 1
VikramV
  • 1,111
  • 2
  • 13
  • 31
  • Ok thanks. And after, how can i set this file for my FragmentActivity?$ – wawanopoulos Jun 16 '14 at 12:20
  • You would require to include the theme in the android manifest file for that particular activity. – VikramV Jun 16 '14 at 12:23
  • Do you know where i can change the color of action bar text ? – wawanopoulos Jun 16 '14 at 13:37
  • You can change that through your Java code or through styles.xml (already stated in my answer). – VikramV Jun 16 '14 at 13:43
  • I have updated my post with the compleete style file that i have generated with your link. There is no text color line. Where i must add this line ? – wawanopoulos Jun 16 '14 at 13:45
  • Sorry for the delayed reply. That link would typically generate all the assets for customizing the action bar with multiple tabs. For text color, you would require to modify your styles.xml `` – VikramV Jun 17 '14 at 04:48
  • I must put this code in my generated style.xml file from your provided link or in my default styles.xml file which is empty? Because i tried to put this code into my generatel xml file and the text stays in black color. Should i modify also the name "MyTheme.ActionBar.TitleTextStyle" ? – wawanopoulos Jun 17 '14 at 06:18