I have three top-level destination fragments in my activity:
appBarConfiguration = AppBarConfiguration(
setOf(
R.id.trackerFragment,
R.id.nutrientFragment,
R.id.settingsFragment
),
drawerLayout
)
Which means all these fragments will show the hamburger button instead of the normal back arrow. The problem is that I have a "Go to Nutrient" button in my App that navigates to NutrientFragment, which is a top level destination. I would like that this fragment still showed the hamburger icon when navigating with the drawer, but a normal back/up button when navigating through the "Go to Nutrient" button.
My initial idea was to pass a boolean value as an argument when navigating to NutrientFragment
, and inside onCreateView()
, depending on the value of the boolean, remove the hamburger icon or add the back button. But that seems a little ugly and inefficient, specially if in the future I add more destinations that could have the same problem. I also have no idea how to "remove the hamburger icon and replace with the normal back button" either. Any idea on how to implement that? All the answers that I found are either in old deprecated java code or not quite what I am looking for.
Thanks.
appBarConfiguration
; if you have a custom design, you need to revert back to customize it with android API, and in your case like((requireActivity() as AppCompatActivity).supportActionBar)?.setDisplayHomeAsUpEnabled(boolean)
– Imbibe