由网友(久伴我者必永驻我心)分享简介:我做的应用程序TabHost甲酸,该选项卡具有默认的颜色显示,是否有可能改变默认的颜色,以我们自己的颜色?我有一些想法,从谷歌,I am doing application with TabHost formate, The tab is displaying with Default color, is there...
我做的应用程序TabHost甲酸,该选项卡具有默认的颜色显示,是否有可能改变默认的颜色,以我们自己的颜色?我有一些想法,从谷歌,
I am doing application with TabHost formate, The tab is displaying with Default color, is there any possibility to change default color to our own color.? I got some ideas from google,
tabHost.setOnTabChangedListener(new OnTabChangeListener(){
@Override
public void onTabChanged(String tabId) {
// TODO Auto-generated method stub
for(int i=0;i<tabHost.getTabWidget().getChildCount();i++)
{
tabHost.getTabWidget().getChildAt(i).setBackgroundColor(R.color.transparent); //unselected
}
tabHost.getTabWidget().getChildAt(tabHost.getCurrentTab()).setBackgroundColor(Color.parseColor("#000011")); // selected
}
每当我这样做,我得到强制关闭错误。如果有改变背景颜色的想法的人,请指导我。
whenever i doing this i am getting force close error. if anyone having idea of changing background color, pls guide me.
推荐答案
您需要先更改默认appearence
You need first to change the default appearence
for(int i=0;i<tabHost.getTabWidget().getChildCount();i++)
{
if (i == 0) tabHost.getTabWidget().getChildAt(i).setBackgroundColor(Color.parseColor("#FFFFFF"));
else tabHost.getTabWidget().getChildAt(i).setBackgroundColor(Color.parseColor("#7392B5"));
}
处理 onTabChanged
事件之前
tabHost.setOnTabChangedListener(new OnTabChangeListener(){
@Override
public void onTabChanged(String tabId) {
// TODO Auto-generated method stub
for(int i=0;i<tabHost.getTabWidget().getChildCount();i++)
{
tabHost.getTabWidget().getChildAt(i).setBackgroundColor(Color.parsecolor("#7392B5")); //unselected
}
tabHost.getTabWidget().getChildAt(tabHost.getCurrentTab()).setBackgroundColor(Color.parseColor("#FFFFFF")); // selected
}
});
相关推荐
最新文章