title: How to hide toolbar from home screen?
body: <p>I am building an android application which requires login. I am using tool bar not the action bar and also have a navigation drawer installed with a bottom navigation. I successfully hid the the bottom navigation from the home screen but the menu from which settings is accessed from the tool bar are still their which may lead the user to access the app without logging in. I want to remove the the settings menu item from the home screen (login screen)
  The Login Screen looks like this  <a href="https://i.stack.imgur.com/vQtfv.jpg" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/vQtfv.jpg" alt="" /></a></p>
  <p>MainActivity.KT:</p>
  <pre><code>package com.example.integratedmodulateoroperationroom
  
  import androidx.appcompat.app.AppCompatActivity
  import android.os.Bundle
  import android.view.Menu
  import android.view.MenuItem
  import android.view.View
  import androidx.navigation.NavController
  import androidx.navigation.fragment.NavHostFragment
  import androidx.navigation.fragment.findNavController
  import androidx.navigation.ui.*
  import com.google.android.material.bottomnavigation.BottomNavigationView
  import kotlinx.android.synthetic.main.activity_main.*
  
  class MainActivity : AppCompatActivity() {
      private lateinit var navController: NavController
      private lateinit var appBarConfiguration: AppBarConfiguration
      override fun onCreate(savedInstanceState: Bundle?) {
          super.onCreate(savedInstanceState)
          setContentView(R.layout.activity_main)
  
          val navHostFragment = supportFragmentManager.findFragmentById(R.id.nav_host_fragment) as NavHostFragment
          navController = navHostFragment.findNavController()
  
          appBarConfiguration = AppBarConfiguration(
              setOf(R.id.homeFragment, R.id.loginFragment),
              drawer_layout
          )
  
          setSupportActionBar(toolbar)
          setupActionBarWithNavController(navController, appBarConfiguration)
  
          bottom_nav.setupWithNavController(navController)
          val bottomNavigationView = findViewById&lt;BottomNavigationView&gt;(R.id.bottom_nav)
  
          navController.addOnDestinationChangedListener { _, destination, _ -&gt;
              bottomNavigationView.visibility = if(destination.id == R.id.loginFragment) {
                  View.GONE
              } else {
                  View.VISIBLE
              }
          }
          nav_view.setupWithNavController(navController)
      }
  
      override fun onCreateOptionsMenu(menu: Menu?): Boolean {
          menuInflater.inflate(R.menu.options_menu, menu)
          return true
      }
  
      override fun onOptionsItemSelected(item: MenuItem): Boolean {
          return item.onNavDestinationSelected(navController) || super.onOptionsItemSelected(item)
      }
  
      override fun onSupportNavigateUp(): Boolean {
          return navController.navigateUp(appBarConfiguration) || super.onSupportNavigateUp()
      }
  }
  </code></pre>
  <p>activity_main.XML:</p>
  <pre><code>&lt;?xml version=&quot;1.0&quot; encoding=&quot;utf-8&quot;?&gt;
  &lt;androidx.drawerlayout.widget.DrawerLayout
      xmlns:android=&quot;http://schemas.android.com/apk/res/android&quot;
      xmlns:app=&quot;http://schemas.android.com/apk/res-auto&quot;
      xmlns:tools=&quot;http://schemas.android.com/tools&quot;
      android:id=&quot;@+id/drawer_layout&quot;
      android:layout_width=&quot;match_parent&quot;
      android:layout_height=&quot;match_parent&quot;
      tools:context=&quot;.MainActivity&quot;&gt;
  
      &lt;androidx.constraintlayout.widget.ConstraintLayout
          android:layout_width=&quot;match_parent&quot;
          android:layout_height=&quot;match_parent&quot;&gt;
  
      &lt;androidx.appcompat.widget.Toolbar
          android:id=&quot;@+id/toolbar&quot;
          android:layout_width=&quot;match_parent&quot;
          android:layout_height=&quot;wrap_content&quot;
          android:background=&quot;@color/design_default_color_primary&quot;
          android:theme=&quot;@style/ThemeOverlay.AppCompat.Dark.ActionBar&quot;
          app:layout_constraintEnd_toEndOf=&quot;parent&quot;
          app:layout_constraintStart_toStartOf=&quot;parent&quot;
          app:layout_constraintTop_toTopOf=&quot;parent&quot;
          app:popupTheme=&quot;@style/ThemeOverlay.AppCompat.Light&quot; /&gt;
  
      &lt;androidx.fragment.app.FragmentContainerView
          android:id=&quot;@+id/nav_host_fragment&quot;
          android:name=&quot;androidx.navigation.fragment.NavHostFragment&quot;
          android:layout_width=&quot;match_parent&quot;
          android:layout_height=&quot;0dp&quot;
          app:defaultNavHost=&quot;true&quot;
          app:layout_constraintBottom_toTopOf=&quot;@+id/bottom_nav&quot;
          app:layout_constraintEnd_toEndOf=&quot;parent&quot;
          app:layout_constraintStart_toStartOf=&quot;parent&quot;
          app:layout_constraintTop_toBottomOf=&quot;@+id/toolbar&quot;
          app:navGraph=&quot;@navigation/nav_graph&quot; /&gt;
  
      &lt;com.google.android.material.bottomnavigation.BottomNavigationView
          android:id=&quot;@+id/bottom_nav&quot;
          android:layout_width=&quot;match_parent&quot;
          android:layout_height=&quot;wrap_content&quot;
          app:layout_constraintBottom_toBottomOf=&quot;parent&quot;
          app:layout_constraintEnd_toEndOf=&quot;parent&quot;
          app:layout_constraintStart_toStartOf=&quot;parent&quot;
          app:menu=&quot;@menu/bottom_nav_menu&quot; /&gt;
  
      &lt;/androidx.constraintlayout.widget.ConstraintLayout&gt;
  
      &lt;com.google.android.material.navigation.NavigationView
          android:id=&quot;@+id/nav_view&quot;
          android:layout_gravity=&quot;start&quot;
          app:menu=&quot;@menu/drawer_nav_menu&quot;
          android:layout_width=&quot;wrap_content&quot;
          android:layout_height=&quot;match_parent&quot; /&gt;
  
  &lt;/androidx.drawerlayout.widget.DrawerLayout&gt;
  </code></pre>
  <p>fragment_login.XML (home screen):</p>
  <pre><code>&lt;androidx.core.widget.NestedScrollView
      xmlns:android=&quot;http://schemas.android.com/apk/res/android&quot;
      xmlns:app=&quot;http://schemas.android.com/apk/res-auto&quot;
      xmlns:tools=&quot;http://schemas.android.com/tools&quot;
      android:layout_height=&quot;match_parent&quot;
      android:layout_width=&quot;match_parent&quot;&gt;
  
  &lt;androidx.constraintlayout.widget.ConstraintLayout
      android:layout_width=&quot;match_parent&quot;
      android:layout_height=&quot;match_parent&quot;
      tools:context=&quot;.LoginFragment&quot;&gt;
  
      &lt;androidx.constraintlayout.utils.widget.ImageFilterView
          android:id=&quot;@+id/login_logo&quot;
          android:layout_width=&quot;match_parent&quot;
          android:layout_height=&quot;300dp&quot;
          android:layout_gravity=&quot;center&quot;
          android:layout_marginStart=&quot;24dp&quot;
          android:layout_marginLeft=&quot;24dp&quot;
          android:layout_marginEnd=&quot;24dp&quot;
          android:layout_marginRight=&quot;24dp&quot;
          android:src=&quot;@drawable/logo&quot;
          app:layout_constraintEnd_toEndOf=&quot;parent&quot;
          app:layout_constraintStart_toStartOf=&quot;parent&quot;
          app:layout_constraintTop_toTopOf=&quot;parent&quot; /&gt;
  
      &lt;com.google.android.material.textfield.TextInputLayout
          android:id=&quot;@+id/Username&quot;
          style=&quot;@style/Widget.MaterialComponents.TextInputLayout.OutlinedBox&quot;
          android:layout_width=&quot;match_parent&quot;
          android:layout_height=&quot;wrap_content&quot;
          android:layout_marginStart=&quot;24dp&quot;
          android:layout_marginLeft=&quot;24dp&quot;
          android:layout_marginEnd=&quot;24dp&quot;
          android:layout_marginRight=&quot;24dp&quot;
          android:hint=&quot;Login ID&quot;
          app:layout_constraintEnd_toEndOf=&quot;parent&quot;
          app:layout_constraintStart_toStartOf=&quot;parent&quot;
          app:layout_constraintTop_toBottomOf=&quot;@+id/login_logo&quot;&gt;
  
          &lt;com.google.android.material.textfield.TextInputEditText
              android:layout_width=&quot;match_parent&quot;
              android:layout_height=&quot;wrap_content&quot;&gt;
  
          &lt;/com.google.android.material.textfield.TextInputEditText&gt;
  
      &lt;/com.google.android.material.textfield.TextInputLayout&gt;
  
      &lt;com.google.android.material.textfield.TextInputLayout
          android:id=&quot;@+id/Password&quot;
          style=&quot;@style/Widget.MaterialComponents.TextInputLayout.OutlinedBox&quot;
          android:layout_width=&quot;match_parent&quot;
          android:layout_height=&quot;wrap_content&quot;
          android:layout_marginStart=&quot;24dp&quot;
          android:layout_marginLeft=&quot;24dp&quot;
          android:layout_marginTop=&quot;16dp&quot;
          android:layout_marginEnd=&quot;24dp&quot;
          android:layout_marginRight=&quot;24dp&quot;
          android:hint=&quot;Password&quot;
          app:layout_constraintEnd_toEndOf=&quot;parent&quot;
          app:layout_constraintStart_toStartOf=&quot;parent&quot;
          app:layout_constraintTop_toBottomOf=&quot;@+id/Username&quot;
          app:passwordToggleEnabled=&quot;true&quot;&gt;
  
          &lt;com.google.android.material.textfield.TextInputEditText
              android:layout_width=&quot;match_parent&quot;
              android:layout_height=&quot;wrap_content&quot;
              android:inputType=&quot;textPassword&quot;&gt;
  
          &lt;/com.google.android.material.textfield.TextInputEditText&gt;
  
      &lt;/com.google.android.material.textfield.TextInputLayout&gt;
  
      &lt;Button
          android:id=&quot;@+id/button2&quot;
          android:layout_width=&quot;200dp&quot;
          android:layout_height=&quot;wrap_content&quot;
          android:layout_gravity=&quot;right&quot;
          android:layout_marginStart=&quot;150dp&quot;
          android:layout_marginLeft=&quot;150dp&quot;
          android:layout_marginTop=&quot;24dp&quot;
          android:background=&quot;#00000000&quot;
          android:text=&quot;Forgot Password?&quot;
          android:textColor=&quot;@color/material_on_surface_emphasis_high_type&quot;
          app:layout_constraintEnd_toEndOf=&quot;parent&quot;
          app:layout_constraintStart_toStartOf=&quot;parent&quot;
          app:layout_constraintTop_toBottomOf=&quot;@+id/Password&quot; /&gt;
  
      &lt;Button
          android:id=&quot;@+id/button_goToHomeScreen&quot;
          android:layout_width=&quot;270dp&quot;
          android:layout_height=&quot;60dp&quot;
          android:layout_gravity=&quot;center&quot;
          android:layout_marginTop=&quot;50dp&quot;
          android:layout_marginBottom=&quot;50dp&quot;
          android:background=&quot;@drawable/button_design&quot;
          android:shadowColor=&quot;#A8A8A8&quot;
          android:shadowDx=&quot;0&quot;
          android:shadowDy=&quot;0&quot;
          android:shadowRadius=&quot;5&quot;
          android:text=&quot;Login&quot;
          android:textAllCaps=&quot;false&quot;
          app:backgroundTint=&quot;@null&quot;
          app:layout_constraintBottom_toBottomOf=&quot;parent&quot;
          app:layout_constraintEnd_toEndOf=&quot;parent&quot;
          app:layout_constraintStart_toStartOf=&quot;parent&quot;
          app:layout_constraintTop_toBottomOf=&quot;@+id/button2&quot; /&gt;
  
  
  &lt;/androidx.constraintlayout.widget.ConstraintLayout&gt;
  &lt;/androidx.core.widget.NestedScrollView&gt;
  </code></pre>