TabHost每个选项卡的字体颜色怎么修改
1个回答
推荐于2017-11-27 · 知道合伙人软件行家
关注
展开全部
TabWidget tabWidget = tabHost.getTabWidget(); //获取TabHost的头部
for (int i=0; i<tabWidget.getChildCount(); i++){ //循环每个tabView
View view = tabWidget.getChildAt(i); //获取tabView项
view.setContentDescription(Integer.toString(i+1));
view.getLayoutParams().height = (int) (view.getLayoutParams().height / 1.2);
//ImageView imageView = (ImageView) view.findViewById(android.R.id.icon); //获取当前选择的图标
//TextView textView = (TextView) view.findViewById(android.R.id.title); //获取textView控件
//imageView.setImageDrawable(getResources().getDrawable(android.R.drawable.ic_menu_slideshow)); //改变我们需要的图标
switch (i) {
case 0:{
view.setBackgroundResource(R.drawable.menu_1_selector);
break;
}
case 1:{
view.setBackgroundResource(R.drawable.menu_2_selector);
break;
}
case 2:{
view.setBackgroundResource(R.drawable.menu_3_selector);
break;
}
case 3:{
view.setBackgroundResource(R.drawable.menu_4_selector);
break;
}
}
/*
if(i == 0){
view.setBackgroundResource(R.drawable.tab_1_selector); //设置背景以后重新设置背景图片
}else if(i == 1){
view.setBackgroundResource(R.drawable.tab_2_selector);
}else if(i == 2){
view.setBackgroundResource(R.drawable.tab_3_selector);
}
TextView textView = (TextView) view.findViewById(android.R.id.title); //获取textView控件
RelativeLayout.LayoutParams params = (RelativeLayout.LayoutParams) textView.getLayoutParams();
params.addRule(RelativeLayout.ALIGN_PARENT_BOTTOM, 0); //取消文字底边对齐
params.addRule(RelativeLayout.CENTER_IN_PARENT, RelativeLayout.TRUE); //设置TextView的文字居中
textView.getPaint().setFakeBoldText(true); //字体加粗
if (tabHost.getCurrentTab() == i) { //如果当前的标签为选中,则将字体放大,并改变其颜色
textView.setTextSize(16);
textView.setTextColor(Color.parseColor("#ff6600")); //选中时的字体颜色
} else {
textView.setTextSize(14);
textView.setTextColor(Color.parseColor("#FFFFFF"));
}
*/
}
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询