My app has an item selection just like WhatsApp and on long click I can select multiple items to delete them. Everything is working fine until I need a button to clear selection. I want to use the back button (arrow) to clear the selection and I want the back arrow to disappear after clicked but I couldn't find a way to do that.
supportActionBar?.setDisplayHomeAsUpEnabled(false)
This would be the first solution but I think it cant hide the button programmatically.
I tried doing this too because I do this with the bin icon to delete but it didn't work with the back arrow.
toolbarMainActivity.menu.findItem(R.id.home).isVisible = false
I also tried changing values in the toolbar, appbar layout and the menu_main.xml file but couldn't set gravity or force the icon to the position of the back arrow before the app title.
This works on app start but after setting it to true setting it to false doesn't hide the arrow, only recreating
supportActionBar?.setDisplayHomeAsUpEnabled(false)
![1]: https://i.sstatic.net/AGFJm.png "tooltip"
I just want to hide the back button after pressing it to clear selection.