Poras Bhardwaj
Poras Bhardwaj

Reputation: 1123

Disable ShiftNode of BottomNavigationView in support library 28.0.0

After upgrading support library to v-28.0.0 BottomNavigationView shift mode not disabling. Even I am using app:labelVisibilityMode="labeled" but items are shifting & item text gets cut on selection.

Previously I was using reflections to do this. Is there any other way to disable shift mode.

Upvotes: 1

Views: 1517

Answers (3)

Fadzli Razali
Fadzli Razali

Reputation: 165

To me, in XML enable the shifting mode used, with match_parent width

            app:labelVisibilityMode="selected"

Disable shifting mode used

            app:labelVisibilityMode="labeled"

& remove your reflections. Mine works as usual.

Upvotes: 3

Jason Grife
Jason Grife

Reputation: 1317

Try setting app:itemTextAppearanceActive and app:itemTextAppearanceInactive to the same textAppearance style, or ones that have the same textSize and fontFamily

Upvotes: 0

Z3nk
Z3nk

Reputation: 395

maybe this can help (it's kotlin) :

@SuppressLint("RestrictedApi")
fun disableShiftMode(view: BottomNavigationView) {
    val menuView = view.getChildAt(0) as BottomNavigationMenuView
    try {
        val shiftingMode = menuView.javaClass.getDeclaredField("mShiftingMode")
        shiftingMode.isAccessible = true
        shiftingMode.setBoolean(menuView, false)
        shiftingMode.isAccessible = false
        for (i in 0 until menuView.childCount) {
            val item = menuView.getChildAt(i) as BottomNavigationItemView
            item.setShiftingMode(false)
            // set once again checked value, so view will be updated
            item.setChecked(item.itemData.isChecked)
        }
    } catch (e: NoSuchFieldException) {
        Log.e(TAG, "Unable to get shift mode field")
    } catch (e: IllegalAccessException) {
        Log.e(TAG, "Unable to change value of shift mode");
    }
}

Upvotes: 0

Related Questions