private void getTv() { BottomNavigationMenuView menuView = (BottomNavigationMenuView) bottomNavigationView.getChildAt(0); BottomNavigationItemView itemView = (BottomNavigationItemView) menuView.getChildAt(0); try { Field tv2 = itemView.getClass().getDeclaredField("largeLabel"); tv2.setAccessible(true); TextView textView = (TextView) tv2.get(itemView); // 获取textView实例 textView.setText("text4"); textView.setVisibility(View.VISIBLE); tv2.set(itemView, textView); } catch (NoSuchFieldException | IllegalAccessException e) { e.printStackTrace(); } }
//反射viewpager
try {
Class c = Class.forName("android.support.v4.view.ViewPager");
Field field =c.getDeclaredField("mOffscreenPageLimit");
field.setAccessible(true);
field.setInt(this, limit);
Class clazz = this.getClass();
Method m1 = clazz.getDeclaredMethod("populate");
m1.invoke(this);
} catch (Exception e) {
e.printStackTrace();
}