Android选项卡文本颜色
可能重复:Android选项卡文本颜色,android,android-text-color,Android,Android Text Color,可能重复: 如何更改android选项卡中的文本颜色。您可以使用以下代码 TabHost tabHost = getTabHost(); for(int i=0;i<tabhost.getTabWidget().getChildCount();i++) { TextView tv = (TextView) tabhost.getTabWidget().getChildAt(i).findViewById(android.R.id.tit
如何更改android选项卡中的文本颜色。您可以使用以下代码
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"))
TabHost TabHost=getTabHost();
对于(int i=0;i我使用,发现它更优雅。下面是一个示例:
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>
什么的文本颜色?你可以在文本视图上使用android:textColor来设置文本的颜色。选项卡必须包含其他视图。此解决方案比其他发布的解决方案干净得多。其工作原理,此帖子简单,状态向前,节省了我的时间,谢谢。ColorStateList是更好的方法。谢谢。非常有效
android:textColor="@color/tab_text"