Search in sources :

Example 1 with BottomNavigationItemView

use of com.google.android.material.bottomnavigation.BottomNavigationItemView in project BaseProject by fly803.

the class BottomNavigationViewHelper method disableShiftMode.

@SuppressLint({ "RestrictedApi", "WrongConstant" })
public static void disableShiftMode(BottomNavigationView navigationView) {
    BottomNavigationMenuView menuView = (BottomNavigationMenuView) navigationView.getChildAt(0);
    try {
        Field shiftingMode = menuView.getClass().getDeclaredField("mShiftingMode");
        shiftingMode.setAccessible(true);
        shiftingMode.setBoolean(menuView, false);
        shiftingMode.setAccessible(false);
        for (int i = 0; i < menuView.getChildCount(); i++) {
            BottomNavigationItemView itemView = (BottomNavigationItemView) menuView.getChildAt(i);
            itemView.setLabelVisibilityMode(0);
            itemView.setShifting(false);
            // itemView.setShiftingMode(false);
            itemView.setChecked(itemView.getItemData().isChecked());
        }
    } catch (NoSuchFieldException | IllegalAccessException e) {
        e.printStackTrace();
    }
}
Also used : Field(java.lang.reflect.Field) BottomNavigationMenuView(com.google.android.material.bottomnavigation.BottomNavigationMenuView) BottomNavigationItemView(com.google.android.material.bottomnavigation.BottomNavigationItemView) SuppressLint(android.annotation.SuppressLint) SuppressLint(android.annotation.SuppressLint)

Aggregations

SuppressLint (android.annotation.SuppressLint)1 BottomNavigationItemView (com.google.android.material.bottomnavigation.BottomNavigationItemView)1 BottomNavigationMenuView (com.google.android.material.bottomnavigation.BottomNavigationMenuView)1 Field (java.lang.reflect.Field)1