设置TabHost中的Tab标签大小,字体的颜色,下划线的长度,使Tab之间可以有间隔

版权声明:本文为博主原创文章,未经博主允许不得转载。 https://blog.csdn.net/ya977896216/article/details/52056190

private void updateTab(final TabHost tabHost) {
for (int i = 0; i < tabHost.getTabWidget().getChildCount(); i++) {
View view = tabHost.getTabWidget().getChildAt(i);
LinearLayout.LayoutParams params = new LinearLayout.LayoutParams(300, 120);
params.setMargins(60, 0, 60, 0);//设置Tab之间的间隔
view.setLayoutParams(params);
TextView tv = (TextView) tabHost.getTabWidget().getChildAt(i).findViewById(android.R.id.title);
// tv.setTextSize(16);//设置标题字体大小
// tv.setTypeface(Typeface.SERIF, 2); // 设置字体和风格
if (tabHost.getCurrentTab() == i) {//选中
tv.setTextColor(this.getResources().getColorStateList(
R.color.app_blue));//Tab被选中的时候标题的颜色
} else {//不选中
tv.setTextColor(this.getResources().getColorStateList(
android.R.color.black));//Tab被不选中的时候标题的颜色
}
}
}

猜你喜欢

转载自blog.csdn.net/ya977896216/article/details/52056190