api 28.0.0 找不到setShiftingMode


API28.0.0
没有 setShiftingMode

<android.support.design.widget.BottomNavigationView
app:labelVisibilityMode="labeled" />

API28以前的方法

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
        item.setShiftingMode(false);
        // 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);
}

}
}

声明:本网站采用BY-NC-SA协议进行授权

版权:LeoROM丨FusionLeo内核丨三星S9丨三星S8|版权所有,违者必究|如未注明,均为原创

转载:转载请注明原文链接 - api 28.0.0 找不到setShiftingMode


不忘初心 方得始终