Challenge - 5 Problems
Navigation Drawer Master
Get all challenges correct to earn this badge!
Test your skills under time pressure!
❓ ui_behavior
intermediate1:30remaining
What happens when the navigation drawer is opened?
In an Android app using a navigation drawer, what is the typical behavior when the drawer is opened?
Attempts:
2 left
💡 Hint
Think about how the main screen moves when the drawer opens.
✗ Incorrect
The navigation drawer typically slides in from the left, pushing the main content to the right to reveal the drawer.
❓ lifecycle
intermediate1:30remaining
When should you close the navigation drawer?
In an Android app with a navigation drawer, when is the best time to close the drawer programmatically?
Attempts:
2 left
💡 Hint
Think about user experience after selecting an option.
✗ Incorrect
Closing the drawer right after a menu item is selected improves user experience by showing the new content clearly.
advanced
2:00remaining
Which code snippet correctly sets up a navigation drawer toggle?
Given an Activity with a DrawerLayout and a Toolbar, which Kotlin code correctly sets up the ActionBarDrawerToggle to sync the drawer icon?
Android Kotlin
val drawerLayout: DrawerLayout = findViewById(R.id.drawer_layout) val toolbar: Toolbar = findViewById(R.id.toolbar)
Attempts:
2 left
💡 Hint
Check the constructor parameters and method names carefully.
✗ Incorrect
Option A uses the correct constructor parameters and method names to set up the toggle properly.
📝 Syntax
advanced1:30remaining
What error does this code produce?
Consider this Kotlin code snippet inside an Activity:
val drawerLayout = findViewById(R.id.drawer_layout)
val toggle = ActionBarDrawerToggle(this, drawerLayout, toolbar, R.string.open, R.string.close)
drawerLayout.addDrawerListener(toggle)
// Missing toggle.syncState() call
What is the likely result when running the app?
Attempts:
2 left
💡 Hint
Think about what syncState() does for the toggle.
✗ Incorrect
Without calling syncState(), the drawer toggle icon is not properly synced with the drawer state, so it won't appear or respond.
🔧 Debug
expert2:00remaining
Why does the navigation drawer not close on back press?
An Android app uses a navigation drawer. The developer overrides onBackPressed() as follows:
override fun onBackPressed() {
super.onBackPressed()
if (drawerLayout.isDrawerOpen(GravityCompat.START)) {
drawerLayout.closeDrawer(GravityCompat.START)
}
}
What is the problem with this code?
Attempts:
2 left
💡 Hint
Consider the order of operations in onBackPressed().
✗ Incorrect
Calling super.onBackPressed() first causes the activity to handle back press and possibly finish before the drawer can close, so the drawer never closes.