如何在android中以编程方式更改所选选项卡的自定义文本颜色?

时间:2013-11-19 07:29:41

标签: android android-tabhost textview android-tabs

我正在为我的应用程序使用tab小部件。我的代码是main.xml http://pastie.org/8491814和tab_layout.xml http://pastie.org/8491816。在这个main.xml中,我为选项卡文本创建了单独的线性布局。我可以在使用选择器选择选项卡时更改选项卡图像。现在我想在选择标签时更改文本视图颜色。我的TabActivity http://pastie.org/8491823。如何选择标签的文本视图颜色?有谁能够帮我?提前谢谢。

1 个答案:

答案 0 :(得分:2)

试试这个:

 for (int i = 0;i<mTabHost.getTabWidget().getChildCount(); i++) {
                 mTabHost.getTabWidget().getChildAt(i).setBackgroundResource(R.drawable.tab);
                 TextView tv = (TextView) mTabHost.getTabWidget().getChildAt(i).findViewById(android.R.id.title);
                 tv.setTextColor(Color.parseColor("#000000"));
             }
             TextView t = (TextView) mTabHost.getCurrentTabView().findViewById(android.R.id.title); //for Selected Tab
             t.setTextColor(Color.parseColor("#FFFFFF"));

您可以更改标签文本的颜色和标签

的背景