如何改变Android tab 的高度和字体大小

这篇博客介绍了如何更改Android TabHost中Tab的高度和字体大小,通过遍历TabWidget的子视图,设置布局参数的高度和TextView的字体大小,同时动态改变选中Tab的背景颜色。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >


  int count = tabWidget.getChildCount();//TabHost中有一个getTabWidget()的方法
  for (int i = 0; i < count; i++) {
   View view = tabWidget.getChildTabViewAt(i);   
   view.getLayoutParams().height = 80; //tabWidget.getChildAt(i)
   final TextView tv = (TextView) view.findViewById(android.R.id.title);
   tv.setTextSize(28);
   tv.setTextColor(this.getResources().getColorStateList(
     android.R.color.white));
  }

//解释二************************************************************************ 
int width =45; 
int height =48; 
for(int i = 0; i < tabWidget.getChildCount(); i++) 

//设置高度、宽度,不过宽度由于设置为fill_parent,在此对它没效果 
tabWidget.getChildAt(i).getLayoutParams().height = height; 
tabWidget.getChildAt(i).getLayoutParams().width = width; 
/** 
* 下面是设置Tab的背景,可以是颜色,背景图片等 
*/ 
View v = tabWidget.getChildAt(i); 
if (tabHost.getCurrentTab() == i) { 
v.setBackgroundColor(Color.GREEN); 
//在这里最好自己设置一个图片作为背景更好 
//v.setBackgroundDrawable(getResources().getDrawable(R.drawable.chat)); 
} else { 
v.setBackgroundColor(Color.GRAY); 


评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值