Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Change text color and selector in TabWidget

I've a TabWidget, independently of the ÀctionBar, in aFragmentTabHost`.

I want to customize the look and feel of the TabWidget but I don't get it. My intention is to change the text color and the selector color, as you can see in the image I can change the background of the TabWidget. I don't want to use a custom TextViewfor the tabs because the tabs must be with the Holo look and feel.

TabWidget

I've tried to put a style to the TabWidgetbut it doesn't work. In this way:

<TabWidget
            android:id="@android:id/tabs"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:orientation="horizontal"
            style="@style/MyTabs"
            />

and with the style

<style name="MyTabs">
        <item name="android:textColor">@color/white</item>
        <item name="android:background">@drawable/tabs</item>
        <item name="android:backgroundStacked">@color/red_action_bar</item>
    </style>

I've tried to add the style from a theme.xml using theparent="android:Widget.Holo.TabWidget", but nothing happens.

like image 972
Mun0n Avatar asked Apr 04 '14 09:04

Mun0n


1 Answers

I finally find a way to do that. Using this code in the onCreateViewmethod of the Fragment

    for (int i = 0; i < tabHost.getTabWidget().getChildCount(); i++) {
                View v = tabHost.getTabWidget().getChildAt(i);
                v.setBackgroundResource(R.drawable.tabs);

                TextView tv = (TextView) tabHost.getTabWidget().getChildAt(i).findViewById(android.R.id.title);
                tv.setTextColor(getResources().getColor(R.color.white));
}

And setting the bakcground color of the TabWidgetto red

like image 155
Mun0n Avatar answered Oct 17 '22 15:10

Mun0n