Search in sources :

Example 16 with BottomNavigationMenuView

use of android.support.design.internal.BottomNavigationMenuView in project openScale by oliexdev.

the class MainActivity method disableShiftMode.

@SuppressLint("RestrictedApi")
public static void disableShiftMode(BottomNavigationView view) {
    BottomNavigationMenuView menuView = (BottomNavigationMenuView) view.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 item = (BottomNavigationItemView) menuView.getChildAt(i);
            // noinspection RestrictedApi
            item.setShiftingMode(false);
            item.setPadding(0, 20, 0, 0);
            // set once again checked value, so view will be updated
            // noinspection RestrictedApi
            item.setChecked(item.getItemData().isChecked());
        }
    } catch (NoSuchFieldException e) {
        Log.e("BNVHelper", "Unable to get shift mode field", e);
    } catch (IllegalAccessException e) {
        Log.e("BNVHelper", "Unable to change value of shift mode", e);
    }
}
Also used : Field(java.lang.reflect.Field) BottomNavigationMenuView(android.support.design.internal.BottomNavigationMenuView) BottomNavigationItemView(android.support.design.internal.BottomNavigationItemView) SuppressLint(android.annotation.SuppressLint) SuppressLint(android.annotation.SuppressLint)

Aggregations

BottomNavigationMenuView (android.support.design.internal.BottomNavigationMenuView)16 BottomNavigationItemView (android.support.design.internal.BottomNavigationItemView)12 Field (java.lang.reflect.Field)6 TextView (android.widget.TextView)4 SuppressLint (android.annotation.SuppressLint)3 ImageView (android.widget.ImageView)2 Paint (android.graphics.Paint)1 BottomNavigationView (android.support.design.widget.BottomNavigationView)1 Transition (android.support.transition.Transition)1 TransitionSet (android.support.transition.TransitionSet)1 View (android.view.View)1