【问题标题】:Android change tabview's text color not backgroundcolorAndroid更改tabview的文本颜色而不是背景颜色
【发布时间】:2011-05-21 00:20:30
【问题描述】:

我该怎么做?可能吗?

tabhost.getTabWidget().getChildAt(i) 。 setTextColor 还是别的什么..?

【问题讨论】:

    标签: android tabview


    【解决方案1】:

    我猜你可以使用 TabHost.TabSpec.setIndicator(android.view.View view) 传递一个 TextView 根据你的需要配置(彩色)。

    但是我再次重读了您的帖子-可能您的意思是如何更改标签内容的颜色,而我在谈论标签标签...如果是这种情况,很抱歉,请忽略此答案。

    更新

    在你的布局 xml 中做最舒服:

    <?xml version="1.0" encoding="utf-8"?>
    <TabHost xmlns:android="http://schemas.android.com/apk/res/android"
        android:id="@android:id/tabhost"
        android:layout_width="fill_parent"
        android:layout_height="fill_parent">
        <LinearLayout
            android:orientation="vertical"
            android:layout_width="fill_parent"
            android:layout_height="fill_parent">
            <TabWidget
                android:id="@android:id/tabs"
                android:layout_width="fill_parent"
                android:layout_height="wrap_content" />
            <FrameLayout
                android:id="@android:id/tabcontent"
                android:layout_width="fill_parent"
                android:layout_height="fill_parent">
                <TextView 
                    android:id="@+id/textview1"
                    android:layout_width="fill_parent"
                    android:layout_height="fill_parent" 
                    android:text="this is a tab - RED"
                    android:textColor="#FF0000" />
                <TextView 
                    android:id="@+id/textview2"
                    android:layout_width="fill_parent"
                    android:layout_height="fill_parent" 
                    android:text="this is another tab - GREEN"
                    android:textColor="#00FF00" />
                <TextView 
                    android:id="@+id/textview3"
                    android:layout_width="fill_parent"
                    android:layout_height="fill_parent" 
                    android:text="this is a third tab - BLUE"
                    android:textColor="#0000FF" />
            </FrameLayout>
        </LinearLayout>
    </TabHost>
    

    【讨论】:

      【解决方案2】:

      试试ColorStateLists。祝你好运。

      【讨论】:

        【解决方案3】:

        要更改选项卡的文本颜色,您需要获取视图,即设置为选项卡标题的 TextView,您可以像这样进行更改:

        TabHost tabhost = getTabHost();
        for(int i=0;i<tabhost.getTabWidget().getChildCount();i++) 
        {
            TextView tv = (TextView) tabhost.getTabWidget().getChildAt(i).findViewById(android.R.id.title);
            tv.setTextColor(.....);
        } 
        

        希望这会有所帮助....

        【讨论】:

          猜你喜欢
          • 2017-03-25
          • 2018-12-25
          • 1970-01-01
          • 2016-06-02
          • 1970-01-01
          • 1970-01-01
          • 1970-01-01
          • 2017-12-11
          • 1970-01-01
          相关资源
          最近更新 更多