如何在SetIndicator视图中设置文本颜色?

时间:2011-02-03 12:50:42

标签: android tabview

以下是我的TabView活动代码。任何人都知道如何在TabView的SetIndicator视图中设置TextColor?

public class TabView extends TabActivity {
    /** Called when the activity is first created. */
    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.main);
        Resources res=getResources();



        TabHost tabhost=getTabHost();
        TabHost.TabSpec restab;
        Intent intent;

        intent=new Intent().setClass(this, Home.class);

        restab=tabhost.newTabSpec("Home").setIndicator("Home",res.getDrawable(R.drawable.home)).setContent(intent);
        tabhost.addTab(restab);

        intent=new Intent().setClass(this, Search.class);
        restab=tabhost.newTabSpec("Search").setIndicator("Search",res.getDrawable(R.drawable.search_icon1)).setContent(intent);
        tabhost.addTab(restab);

        intent=new Intent().setClass(this, Back.class);
        restab=tabhost.newTabSpec("Back").setIndicator("Back",res.getDrawable(R.drawable.back_icon)).setContent(intent);
        tabhost.addTab(restab);
       for(int i=0;i<tabhost.getTabWidget().getChildCount();i++)
       {


           tabhost.getTabWidget().getChildAt(i).setBackgroundColor(Color.parseColor("#CCCCCC"));
       }

    }
}

1 个答案:

答案 0 :(得分:1)

您可以将TextView用于个人。像这样:

for(int i = 0; i < tabhost.getTabWidget().getChildCount(); i++) {
   tabhost.getTabWidget().getChildAt(i).setBackgroundColor(Color.parseColor("#CCCCCC"));
   TextView textView = (TextView) tabWidget.getChildAt(i).findViewById(android.R.id.title);
   textView.setTextColor(Color.BLACK);
}