Android标签文字颜色

时间:2011-03-01 13:55:11

标签: android android-text-color

  

可能重复:
  Android: Change Tab Text Color Programmatically

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

2 个答案:

答案 0 :(得分: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>

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

android:textColor="@color/tab_text"

答案 1 :(得分: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"))