If you are using navigation UI in your application , if you want to hide your app bar (top bar of your app showing navigation icon) or back navigation arrow in a particular fragment you can do like this in your Mainactivity
In the main activity you have to use OnDestinationChangeListener, in the listener you have to check for destination fragment for which you want to hide the actionBar and hide it.
class MainActivity : AppCompatActivity() { class MainActivity : AppCompatActivity() { private lateinit var drawerlayout : DrawerLayout private lateinit var navView : NavigationView override fun onCreate(savedInstanceState: Bundle?) { super.onCreate(savedInstanceState) setContentView(R.layout.activity_main) drawerlayout = findViewById(R.id.drawer_layout) navView = findViewById(R.id.nav_view) val navController : NavController = this.findNavController(R.id.navhost) NavigationUI.setupActionBarWithNavController(this,navController,drawerlayout) NavigationUI.setupWithNavController(navView,navController) navController.addOnDestinationChangedListener { _, destination, _ -> if(destination.id==R.id.qaFragment){ supportActionBar?.hide() } else{ supportActionBar?.show() } } } override fun onSupportNavigateUp(): Boolean { val navController : NavController = findNavController(R.id.navhost) return NavigationUI.navigateUp(navController,drawerlayout) } }
navController.addOnDestinationChangedListener { _, destination, _ -> if(destination.id==R.id.qaFragment){ supportActionBar?.hide() } else{ supportActionBar?.show() } }
Comments
Post a Comment