0
0
Android Kotlinmobile~20 mins

Navigation drawer in Android Kotlin - Practice Problems & Coding Challenges

Choose your learning style9 modes available
Challenge - 5 Problems
🎖️
Navigation Drawer Master
Get all challenges correct to earn this badge!
Test your skills under time pressure!
ui_behavior
intermediate
1: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?
AThe drawer appears over the main content without moving it.
BThe main content slides to the right and the drawer appears from the left.
CThe main content fades out and the drawer replaces it completely.
DThe drawer slides from the bottom covering the main content.
Attempts:
2 left
💡 Hint
Think about how the main screen moves when the drawer opens.
lifecycle
intermediate
1: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?
AWhen the app is paused or stopped.
BOnly when the user presses the back button.
CImmediately after the user selects a menu item from the drawer.
DNever close it programmatically; let the user close it manually.
Attempts:
2 left
💡 Hint
Think about user experience after selecting an option.
navigation
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)
A
val toggle = ActionBarDrawerToggle(this, drawerLayout, toolbar, R.string.open, R.string.close)
drawerLayout.addDrawerListener(toggle)
toggle.syncState()
B
val toggle = ActionBarDrawerToggle(this, drawerLayout, toolbar)
drawerLayout.addDrawerListener(toggle)
toggle.syncState()
C
val toggle = ActionBarDrawerToggle(drawerLayout, this, toolbar, R.string.open, R.string.close)
drawerLayout.setDrawerListener(toggle)
toggle.syncState()
D
val toggle = ActionBarDrawerToggle(this, drawerLayout, toolbar, R.string.open, R.string.close)
drawerLayout.addDrawerListener(toggle)
toggle.sync()
Attempts:
2 left
💡 Hint
Check the constructor parameters and method names carefully.
📝 Syntax
advanced
1: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?
AThe drawer works perfectly with no issues.
BThe app crashes with a NullPointerException.
CThe drawer opens but the icon animates incorrectly.
DThe drawer icon does not appear or respond to clicks.
Attempts:
2 left
💡 Hint
Think about what syncState() does for the toggle.
🔧 Debug
expert
2: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?
ACalling super.onBackPressed() first closes the activity before the drawer can close.
BThe drawerLayout.isDrawerOpen() method is used incorrectly and always returns false.
CThe drawerLayout.closeDrawer() method requires a delay to work properly.
DThe GravityCompat.START constant is not the correct gravity for the drawer.
Attempts:
2 left
💡 Hint
Consider the order of operations in onBackPressed().