Android标签文字颜色

Alt*_*taf 6 android android-text-color

可能重复:
Android:以编程方式更改选项卡文本颜色

我们如何在android选项卡中更改文本颜色.

isn*_*esh 34

我使用ColorStateList,发现它更优雅.这是一个例子:

tab_text.xml:

<?xml version="1.0" encoding="utf-8"?>
<selector xmlns:android="http://schemas.android.com/apk/res/android">
    <item android:state_selected="true" android:color="@color/tab_active" />
    <item android:state_selected="false" android:color="@color/tab_inactive" />
</selector>
Run Code Online (Sandbox Code Playgroud)

在TextView中,只需将textColor设置为指向此文件:

android:textColor="@color/tab_text"
Run Code Online (Sandbox Code Playgroud)


Tus*_*kar 21

您可以使用以下代码

    TabHost tabHost = getTabHost();
for(int i=0;i<tabhost.getTabWidget().getChildCount();i++) 
        { 
            TextView tv = (TextView) tabhost.getTabWidget().getChildAt(i).findViewById(android.R.id.title); //Unselected Tabs
            tv.setTextColor(Color.parseColor("#ffffff"));
        } 
        TextView tv = (TextView) tabhost.getCurrentTabView().findViewById(android.R.id.title); //for Selected Tab
        tv.setTextColor(Color.parseColor("#000000"))
Run Code Online (Sandbox Code Playgroud)