2

When you register a toolbar with navigation architecture it will create an arrow allowing you to pop up on the fragment you are on.

On a few base level fragments I don't want to have the Hamburger menu icon nor the arrow but a custom view object.

How would I disable the back button from view?

I have tried manually disabling but am having a hard time finding out how to manage it with Navigation arch.

val supportActionBar = activity?.actionBar
    if (supportActionBar != null) {
        supportActionBar.setDisplayShowHomeEnabled(false)
        supportActionBar.setDisplayHomeAsUpEnabled(false)
        supportActionBar.setHomeButtonEnabled(false)
        supportActionBar.setHomeAsUpIndicator(null)
}
Vadim Kotov
  • 8,084
  • 8
  • 48
  • 62
Randy
  • 1,400
  • 2
  • 12
  • 30

2 Answers2

2

Well after a good hour I hope that my pain and oversight really helps someone out. After Navigation Architecture forces you to load up a drawable into the navigation icon the only solution I came up with was to nullify it.

toolbar.navigationIcon = null
Randy
  • 1,400
  • 2
  • 12
  • 30
0

I solved this problem with this:

val actionBar = (activity as AppCompatActivity).supportActionBar
actionBar?.setDisplayHomeAsUpEnabled(false)

Anyway, you should also keep in mind that you need to change navigation graph to set proper popUpTo destination or somehow disable system back button.

Jan Kotas
  • 71
  • 1
  • 3