Created
January 30, 2018 08:37
-
-
Save babedev/ba73db1be6f7662168e759f2c70655d3 to your computer and use it in GitHub Desktop.
Disable shift mode for BottomNavigationView
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
@SuppressLint("RestrictedApi") | |
fun BottomNavigationView.disableShiftMode() { | |
val menuView = this.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) | |
item.setChecked(item.itemData.isChecked) | |
} | |
} catch (e: NoSuchFieldException) { | |
e.printStackTrace() | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
From API28 this works