File tree Expand file tree Collapse file tree 1 file changed +10
-0
lines changed
app/src/main/java/com/example/android/navigation Expand file tree Collapse file tree 1 file changed +10
-0
lines changed Original file line number Diff line number Diff line change @@ -20,6 +20,8 @@ import android.os.Bundle
2020import androidx.appcompat.app.AppCompatActivity
2121import androidx.databinding.DataBindingUtil
2222import androidx.drawerlayout.widget.DrawerLayout
23+ import androidx.navigation.NavController
24+ import androidx.navigation.NavDestination
2325import androidx.navigation.findNavController
2426import androidx.navigation.ui.AppBarConfiguration
2527import androidx.navigation.ui.NavigationUI
@@ -39,6 +41,14 @@ class MainActivity : AppCompatActivity() {
3941// tie the binding object into a view
4042 NavigationUI .setupActionBarWithNavController(this , navController, drawerLayout)
4143 appBarConfiguration = AppBarConfiguration (navController.graph, drawerLayout)
44+ // prevent nav gesture if not on start destination
45+ navController.addOnDestinationChangedListener{ nc : NavController , nd: NavDestination , args: Bundle ? ->
46+ if (nd.id == nc.graph.startDestination) {
47+ drawerLayout.setDrawerLockMode(DrawerLayout .LOCK_MODE_UNLOCKED )
48+ } else {
49+ drawerLayout.setDrawerLockMode(DrawerLayout .LOCK_MODE_LOCKED_CLOSED )
50+ }
51+ }
4252 NavigationUI .setupWithNavController(binding.navView, navController)
4353 }
4454
You can’t perform that action at this time.
0 commit comments