修改圖片字體大卸昴:http://www.reibang.com/p/feab12806ba2
鏈接作者給的靈感懦铺, 看了源碼,給Tab布局設(shè)置背景支鸡,就可以去小水波紋
/*
* @param bottomNavigationBar,需要修改的 BottomNavigationBar
* @param space 圖片與文字之間的間距
* @param imgLen 單位:dp趁窃,圖片大小牧挣,應(yīng) <= 36dp
* @param textSize 單位:dp,文字大小醒陆,應(yīng) <= 20dp
*
* 使用方法:直接調(diào)用setBottomNavigationItem(bottomNavigationBar, 6, 26, 10);
* 代表將bottomNavigationBar的文字大小設(shè)置為10dp瀑构,圖片大小為26dp,二者間間距為6dp
*
* */
private void setBottomNavigationItem(BottomNavigationBar bottomNavigationBar, int space, int imgLen, int textSize) {
Class barClass = bottomNavigationBar.getClass();
Field[] fields = barClass.getDeclaredFields();
for (int i = 0; i < fields.length; i++) {
Field field = fields[i];
field.setAccessible(true);
if (field.getName().equals("mTabContainer")) {
try {
//反射得到 mTabContainer
LinearLayout mTabContainer = (LinearLayout) field.get(bottomNavigationBar);
for (int j = 0; j < mTabContainer.getChildCount(); j++) {
//獲取到容器內(nèi)的各個(gè)Tab
View view = mTabContainer.getChildAt(j);
//獲取到Tab內(nèi)的各個(gè)顯示控件
FrameLayout.LayoutParams params = new FrameLayout.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, dip2px(50));
FrameLayout container = (FrameLayout) view.findViewById(R.id.fixed_bottom_navigation_container);
container.setBackground(null);//刪除水波紋
container.setLayoutParams(params);
container.setPadding(dip2px(12), dip2px(0), dip2px(12), dip2px(0));
//獲取到Tab內(nèi)的文字控件
TextView labelView = (TextView) view.findViewById(com.ashokvarma.bottomnavigation.R.id.fixed_bottom_navigation_title);
//計(jì)算文字的高度DP值并設(shè)置刨摩,setTextSize為設(shè)置文字正方形的對(duì)角線長(zhǎng)度寺晌,所以:文字高度(總內(nèi)容高度減去間距和圖片高度)*根號(hào)2即為對(duì)角線長(zhǎng)度,此處用DP值澡刹,設(shè)置該值即可呻征。
labelView.setTextSize(TypedValue.COMPLEX_UNIT_DIP, textSize);
labelView.setIncludeFontPadding(false);
labelView.setPadding(0, 0, 0, dip2px(20 - textSize - space / 2));
//獲取到Tab內(nèi)的圖像控件
ImageView iconView = (ImageView) view.findViewById(com.ashokvarma.bottomnavigation.R.id.fixed_bottom_navigation_icon);
//設(shè)置圖片參數(shù),其中罢浇,MethodUtils.dip2px():換算dp值
params = new FrameLayout.LayoutParams(dip2px(imgLen), dip2px(imgLen));
params.setMargins(0, 0, 0, space / 2);
params.gravity = Gravity.BOTTOM | Gravity.CENTER_HORIZONTAL;
iconView.setLayoutParams(params);
}
} catch (IllegalAccessException e) {
e.printStackTrace();
}
}
}
}