修改图片字体大小:https://www.jianshu.com/p/feab12806ba2
链接作者给的灵感, 看了源码,给Tab布局设置背景,就可以去小水波纹
/*
* @param bottomNavigationBar,需要修改的 BottomNavigationBar
* @param space 图片与文字之间的间距
* @param imgLen 单位:dp,图片大小,应 <= 36dp
* @param textSize 单位:dp,文字大小,应 <= 20dp
*
* 使用方法:直接调用setBottomNavigationItem(bottomNavigationBar, 6, 26, 10);
* 代表将bottomNavigationBar的文字大小设置为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++) {
//获取到容器内的各个Tab
View view = mTabContainer.getChildAt(j);
//获取到Tab内的各个显示控件
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内的文字控件
TextView labelView = (TextView) view.findViewById(com.ashokvarma.bottomnavigation.R.id.fixed_bottom_navigation_title);
//计算文字的高度DP值并设置,setTextSize为设置文字正方形的对角线长度,所以:文字高度(总内容高度减去间距和图片高度)*根号2即为对角线长度,此处用DP值,设置该值即可。
labelView.setTextSize(TypedValue.COMPLEX_UNIT_DIP, textSize);
labelView.setIncludeFontPadding(false);
labelView.setPadding(0, 0, 0, dip2px(20 - textSize - space / 2));
//获取到Tab内的图像控件
ImageView iconView = (ImageView) view.findViewById(com.ashokvarma.bottomnavigation.R.id.fixed_bottom_navigation_icon);
//设置图片参数,其中,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();
}
}
}
}