1-1:修改间距及图片文字大小的方法
/**
@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(56));
FrameLayout container = (FrameLayout) view.findViewById(R.id.fixed_bottom_navigation_container);
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);