android { ... viewBinding { enabled = true } }
private lateinit var binding: ActivityMainBinding
override fun onCreate(savedInstanceState: Bundle?) { super.onCreate(savedInstanceState)
binding = ActivityMainBinding.inflate(layoutInflater)
setContentView(binding.root)
// 初始化 BottomNavigationView 和 Navigation
...
}
val navView: BottomNavigationView = binding.bottomNav val navController = findNavController(R.id.nav_host_fragment)
appBarConfiguration = AppBarConfiguration( setOf( R.id.navigation_home, R.id.navigation_cart, R.id.navigation_profile ) )
setupActionBarWithNavController(navController, appBarConfiguration) navView.setupWithNavController(navController)