美文网首页
BottomNavigationView系统自带底部菜单栏

BottomNavigationView系统自带底部菜单栏

作者: 苏坡坡要吃婆婆酥 | 来源:发表于2017-06-29 14:12 被阅读0次

    取消动画效果。需要创建一个Helper类。

    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;

    public class BottomNavigationViewHelper {
    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);
    }
    }
    }

    使用:
    BottomNavigationView bottomNavigationView = (BottomNavigationView) findViewById(R.id.bottom_navigation_bar);
    BottomNavigationViewHelper.disableShiftMode(bottomNavigationView);

    相关文章

      网友评论

          本文标题:BottomNavigationView系统自带底部菜单栏

          本文链接:https://www.haomeiwen.com/subject/qnmmcxtx.html