更改文本颜色和选择的TabWidget文本、颜色、TabWidget

由网友(打小脾气傲)分享简介:我有一个 TabWidget ,独立的动作条的,在 FragmentTabHost`。我要定制的外观和感觉的 TabWidget ,但我不明白这一点。我的目的是改变文字颜色,选择颜色,你可以在图片中看到,我可以修改 TabWidget 的背景。我不想使用自定义的的TextView 的标签,因为标签必须与霍洛的外观和感觉...

我有一个 TabWidget ,独立的动作条的,在 FragmentTabHost`。

我要定制的外观和感觉的 TabWidget ,但我不明白这一点。我的目的是改变文字颜色,选择颜色,你可以在图片中看到,我可以修改 TabWidget 的背景。我不想使用自定义的的TextView 的标签,因为标签必须与霍洛的外观和感觉。

我试图把一个风格的 TabWidget ,但它不工作。通过这种方式:

 < TabWidget
            机器人:ID =@机器人:ID /标签
            机器人:layout_width =match_parent
            机器人:layout_height =WRAP_CONTENT
            机器人:方向=横向
            风格=@风格/ MyTabs
            />
 

和的风格

 <样式名称=MyTabs>
        <项目名称=机器人:文字颜色> @色/白< /项目>
        <项目名称=机器人:背景> @可绘制/标签< /项目>
        <项目名称=机器人:backgroundStacked> @色/ red_action_bar< /项目>
    < /风格>
 

我试图使用父=从theme.xml加上风格的Android:Widget.Holo.TabWidget,但没有任何反应。 解决方案

我终于找到一个方法来做到这一点。使用这个code。在片段的 onCreateView 方法

 的for(int i = 0; I< tabHost.getTabWidget()getChildCount();我++){
                视图V = tabHost.getTabWidget()getChildAt(我)。
                v.setBackgroundResource(R.drawable.tabs);

                TextView的电视=(TextView中)tabHost.getTabWidget()getChildAt(我).findViewById(android.R.id.title)。
                tv.setTextColor(getResources()的getColor(R.color.white));
}
 
在qt5中给Tab widget添加Tab框

和设置的bakcground颜色 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.

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.

解决方案

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

阅读全文

相关推荐

最新文章