[英]how to change Action bar icon (hamburger icon) when using navigation drawer with navigation component
[英]how to change toolbar icon (hamburger icon) when using navigation drawer with jetpack navigation component
我正在使用噴氣背包導航組件來構建一個導航抽屜,我想更改工具欄的漢堡圖標,我嘗試了很多像下面這樣的解決方案,但它們不起作用
app:navigationIcon="@drawable/menu"
還
getSupportActionBar().setHomeButtonEnabled(true);
getSupportActionBar().setDisplayHomeAsUpEnabled(true);
getSupportActionBar().setHomeAsUpIndicator(R.drawable.menu);
這是我的代碼
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
setContentView(R.layout.activity_main)
setSupportActionBar(toolbar)
navController=findNavController(R.id.nav_host_fragment)
appBarConfiguration=AppBarConfiguration(setOf(R.id.nav_acceuil,R.id.nav_notifications,R.id.nav_gerer,R.id.nav_deconnexion),drawer_layout)
setupActionBarWithNavController(navController,appBarConfiguration)
nav_view.setupWithNavController(navController);
}
您可以使用addOnDestinationChangedListener
:
navController.addOnDestinationChangedListener { controller, destination, arguments ->
if (destination.id == R.id.nav_xxxx){
supportActionBar?.setHomeAsUpIndicator(R.drawable.xxxx)
}
}
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.