Slide 16
Slide 16 text
対処法②~リフレクションを使う~
lateinit var binding: ActivityMainBinding
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
...
binding = DataBindingUtil.setContentView(this, R.layout.activity_main)
binding.bottomNav.fixBlinking() // 初期化時に下記の拡張関数を呼んであげれば
OK
}
private fun BottomNavigationView.fixBlinking() {
val menuView = getChildAt(0) as BottomNavigationMenuView
with(menuView::class.java.getDeclaredField("set")) {
isAccessible = true
val transitionSet = (get(menuView) as androidx.transition.AutoTransition).apply {
for (i in transitionCount downTo 0) {
val transition = getTransitionAt(i) as? Fade ?: continue
removeTransition(transition)
}
}
set(menuView, transitionSet)
}
}
リフレクションでmenuViewに
アタッチされているFadeTransitionを
removeする
BottomNavigationMenuViewの
transitionSetのプロパティを取得
TransitionSetをセットし
直す