我想用kotlin禁用Shift模式,我使用了材质BottomNavigationView
<com.google.android.material.bottomnavigation.BottomNavigationView
android:id="@+id/bottom_navigation"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_gravity="bottom"
app:itemIconSize="@dimen/iconSize"
android:background="?android:attr/windowBackground"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:menu="@menu/btm_nav_menu"
app:labelVisibilityMode="labeled"
/>
我要单击帐户图标并在单击后退按钮homeFragment时启动活动登录,而不是选择帐户图标
bottom_navigation.setOnNavigationItemSelectedListener {
when(it.itemId) {
R.id.homeFragment -> showNav(HomeFragment())
R.id.accountFragment -> { bottom_navigation.menu.findItem(R.id.homeFragment).setCheckable(true)
startActivity(Intent(this, MainActivity2::class.java)) }
}
true
}
fun showNav(fragment: Fragment){
supportFragmentManager.beginTransaction().apply {
replace(R.id.fragment_container, fragment)
commit()
}
}
答案 0 :(得分:0)
答案2.使用false,底部导航不会选择图标
bottom_navigation.setOnNavigationItemSelectedListener {
when(it.itemId) {
R.id.homeFragment -> {
showNav(HomeFragment())
true
}
R.id.accountFragment -> {
startActivity(Intent(this, MainActivity2::class.java))
false
} else -> true
}
}