您的位置:首页 > 移动开发 > Android开发

改变Android tab的字体大小和颜色

2014-07-23 14:42 288 查看
可以使用TabHost中的getTabWidget()方法
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(12);//设置字体大小
// tv.setTextColor(Color.RED);//设置成红色
tv.setTextColor(this.getResources().getColorStateList( android.R.color.white)); }
解释:tv.setTextSize(12);是可以设置字体大小,但是为了代码的稳定性,不可以直接写数字,要使用带单位的来设置,我在项目中就遇到了这个问题,解决方法是:tv.setTextSize(TypedValue.COMPLEX_UNIT_SP, 24f);//设置成24sp
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(12);//设置字体大小
tv.setTextSize(TypedValue.COMPLEX_UNIT_SP, 24f);
//tv.setTextColor(Color.RED);//设置成红色
       tv.setTextColor(this.getResources().getColorStateList(android.R.color.white));}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: