开发者

Android Tab Text color [duplicate]

开发者 https://www.devze.com 2023-02-13 23:07 出处:网络
This question already has answers here: 开发者_如何学Go Closed 11 years ago. Possible Duplicate: Android: Change Tab Text Color Programmatically
This question already has answers here: 开发者_如何学Go Closed 11 years ago.

Possible Duplicate:

Android: Change Tab Text Color Programmatically

How can we change the text color in android tab.


I use the ColorStateList, find it more elegant. Here is an example :

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>

In your TextView, just set the textColor to point to this file with :

android:textColor="@color/tab_text"


You can use following code

    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"))
0

精彩评论

暂无评论...
验证码 换一张
取 消