我正在尝试使用TextView在tabhost上定义TabWidget的样式.
我刚刚为bgcolor创建了一个选择器并且工作正常,但我想为textColor创建一个选择器,但文本颜色不会改变:
这是我的tab_text_selector.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="@android:color/white" />
<item android:state_focused="true" android:color="@android:color/white" />
<item android:state_pressed="true" android:color="@android:color/white" />
</selector>
Run Code Online (Sandbox Code Playgroud)
当我尝试在textView上使用时,这是代码:
TextView txtTab=new TextView(this);
txtTab.setTextColor(R.drawable.tab_text_selector);
txtTab.setBackgroundResource(R.drawable.tab_bg_selector);
txtTab.setGravity(Gravity.CENTER);
txtTab.setText("Agregar Idea");
Run Code Online (Sandbox Code Playgroud)
我知道文本颜色在任何情况下都必须是白色,但事实并非如此.
试图更改tabhost文本颜色,在此代码中我可以更改tabhost背景颜色(不是文本颜色)
tabHost.setOnTabChangedListener(new OnTabChangeListener() {
@Override
public void onTabChanged(String tabId) {
for (int i = 0; i < tabHost.getTabWidget().getChildCount(); i++) {
tabHost.getTabWidget().getChildAt(i)
.setBackgroundColor(Color.parseColor("#FF0000")); // unselected
}
tabHost.getTabWidget().getChildAt(tabHost.getCurrentTab())
.setBackgroundColor(Color.parseColor("#0000FF")); // selected
}
});
Run Code Online (Sandbox Code Playgroud)
如何更改tabhost文本颜色?