无法在BottomNavigationView中解析方法'setShiftingMode(Boolean)'

问题描述 投票:19回答:1

升级到最新的支持库'28 .0.0-alpha1'后,我无法在BottomNavigationView中禁用移位模式,即BottomNavigationItemView.setShiftingMode()方法不再可用。

java.lang.NoSuchFieldException: No field mShiftingMode in class Landroid/support/design/internal/BottomNavigationMenuView; 
    W/System.err:     at java.lang.Class.getDeclaredField(Native Method)
    at com.avocure.avocurehealth.utils.ViewUtils.removeNavigationShiftMode(ViewUtils.java:44)
    at com.avocure.avocurehealth.ui.main.MainActivity.init(MainActivity.java:125)
    at com.avocure.avocurehealth.ui.main.MainActivity.onCreate(MainActivity.java:107)
    at android.app.Activity.performCreate(Activity.java:6679)
    at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1118)
    at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2618)
    at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2726)
    at android.app.ActivityThread.-wrap12(ActivityThread.java)
    at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1477)
    at android.os.Handler.dispatchMessage(Handler.java:102)
    at android.os.Looper.loop(Looper.java:154)
    at android.app.ActivityThread.main(ActivityThread.java:6119)
    at java.lang.reflect.Method.invoke(Native Method)
    at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:886)
    at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:776)

我使用this方法来禁用移位模式。

如果有人能够了解最新版本中的某些内容是否发生了变化,或者这是一个错误还是其他什么,我们将非常感激。

android android-support-library bottomnavigationview
1个回答
76
投票

找到了答案。在支持库28.0.0-alpha1中,我们现在可以使用以下任何方法添加标签(删除移位模式):

XML:

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

码:

mBottomNavigationView.setLabelVisibilityMode(LabelVisibilityMode.LABEL_VISIBILITY_LABELED);

要么:

@SuppressLint("RestrictedApi")
public static void removeNavigationShiftMode(BottomNavigationView view) {
    BottomNavigationMenuView menuView = (BottomNavigationMenuView) view.getChildAt(0);
    menuView.setLabelVisibilityMode(LabelVisibilityMode.LABEL_VISIBILITY_LABELED);
    menuView.buildMenuView();
}
© www.soinside.com 2019 - 2024. All rights reserved.