Android Kotlin-底部导航禁用切换模式和选择菜单

问题描述

  1. 我想用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"
     />
    
  2. 我要单击帐户图标并在单击后退按钮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()
         }
    }
    

解决方法

暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!

如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。

小编邮箱:dio#foxmail.com (将#修改为@)