本文介绍了Android tabhost 更改文本颜色样式的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
尝试更改 tabhost 文本颜色,在此代码中我可以更改 tabhost 背景颜色(不是文本颜色)
Trying to change tabhost text color, in this code I can change tabhost background color(not text color)
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
}
});
如何更改 tabhost 文本颜色?
how can I change tabhost text color?
推荐答案
您可以按如下方式更改 Tabhost 文本的颜色.
You may change color of Tabhost text as follow.
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
TextView tv = (TextView) tabhost.getTabWidget().getChildAt(i).findViewById(android.R.id.title); //Unselected Tabs
tv.setTextColor(Color.parseColor("#ffffff"));
}
tabHost.getTabWidget().getChildAt(tabHost.getCurrentTab()).setBackgroundColor(Color.parseColor("#0000FF")); // selected
TextView tv = (TextView) tabhost.getCurrentTabView().findViewById(android.R.id.title); //for Selected Tab
tv.setTextColor(Color.parseColor("#000000"))
}
});
要在您的 Activity 中初始设置文本颜色,您可以在 onResume()
函数中使用此代码
To set text color initially in your activity, you can use this code in onResume()
function
TabHost tabhost = getTabHost();
for(int i=0;i<tabhost.getTabWidget().getChildCount();i++)
{
TextView tv = (TextView) tabhost.getTabWidget().getChildAt(i).findViewById(android.R.id.title);
tv.setTextColor(Color.parseColor("#000000"));
}
这篇关于Android tabhost 更改文本颜色样式的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!