2020-08-03 09:11:54 +08:00
|
|
|
package utils;
|
|
|
|
|
|
|
|
|
|
import android.annotation.SuppressLint;
|
|
|
|
|
import android.support.design.internal.BottomNavigationItemView;
|
|
|
|
|
import android.support.design.internal.BottomNavigationMenuView;
|
|
|
|
|
import android.support.design.widget.BottomNavigationView;
|
|
|
|
|
import android.util.Log;
|
|
|
|
|
|
|
|
|
|
import java.lang.reflect.Field;
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Created by 90432 on 2018/1/10.
|
|
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
public class BottomNavigationViewHelper {
|
|
|
|
|
@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
|
2020-08-14 17:07:43 +08:00
|
|
|
// item.setShiftingMode(false);
|
2020-08-03 09:11:54 +08:00
|
|
|
// 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);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|