Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
139 views
in Technique[技术] by (71.8m points)

android - Cannot resolve method 'setShiftingMode(Boolean)' in BottomNavigationView

After upgrading to latest support library '28.0.0-alpha1' I cannot disable shifting mode in my BottomNavigationView i.e. the BottomNavigationItemView.setShiftingMode() method is no longer available.

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)

I use this method to disable shifting mode.

It would be very much appreciated if anyone could shed some light on whether something has changed in the latest version or is this a bug or something.

question from:https://stackoverflow.com/questions/51342200/cannot-resolve-method-setshiftingmodeboolean-in-bottomnavigationview

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

Found the answer. In support library 28.0.0-alpha1 we can now add labels (remove shifting mode) using any one of the following methods:

XML:

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

Code:

mBottomNavigationView.setLabelVisibilityMode(LabelVisibilityMode.LABEL_VISIBILITY_LABELED);

Or:

@SuppressLint("RestrictedApi")
public static void removeNavigationShiftMode(BottomNavigationView view) {
    BottomNavigationMenuView menuView = (BottomNavigationMenuView) view.getChildAt(0);
    menuView.setLabelVisibilityMode(LabelVisibilityMode.LABEL_VISIBILITY_LABELED);
    menuView.buildMenuView();
}

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

1.4m articles

1.4m replys

5 comments

57.0k users

...