BottomNavigationView with more than 3 Items: tab title is hiding

后端 未结 10 884
-上瘾入骨i
-上瘾入骨i 2020-12-07 16:01

I\'m using BottomNavigationView with using Android Support Desing Library 25. But when I switch the tabs, the other tab\'s title is hiding. But there is no hiding issue actu

10条回答
  •  感情败类
    2020-12-07 16:57

    Kotlin extension function:

    @SuppressLint("RestrictedApi")
    fun BottomNavigationView.removeShiftMode(){
        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)
                // set once again checked value, so view will be updated
                item.setChecked(item.itemData.isChecked)
            }
        } catch (e: NoSuchFieldException) {
            e.printStackTrace()
            Timber.tag("BottomNav").e( e, "Unable to get shift mode field")
        } catch (e: IllegalAccessException) {
            Timber.tag("BottomNav").e( e, "Unable to change value of shift mode")
        }
    }
    

提交回复
热议问题