Skip to content

Instantly share code, notes, and snippets.

@AmandaRiu
Created April 21, 2018 01:26
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save AmandaRiu/8073d2221e8423cb27f825c2bd86a895 to your computer and use it in GitHub Desktop.
Save AmandaRiu/8073d2221e8423cb27f825c2bd86a895 to your computer and use it in GitHub Desktop.
Disable android 'BottomNavigationView' shift mode
// Extension function
@SuppressLint("RestrictedApi")
fun BottomNavigationView.disableShiftMode() {
val menuView = getChildAt(0) as BottomNavigationMenuView
try {
val shiftingMode = menuView::class.java.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", e)
} catch (e: IllegalStateException) {
Log.e(TAG, "Unable to change value of shift mode", e)
}
}
// Usage
bottom_navigation_view.disableShiftMode()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment