A Navigation Drawer is a sliding panel that appears from the side of the screen. It shows app navigation options and helps users switch between different sections easily.
Click to reveal answer
beginner
Which layout is commonly used as the root layout to implement a Navigation Drawer?
The DrawerLayout is used as the root layout. It allows the drawer panel to slide in and out over the main content.
Click to reveal answer
intermediate
How do you open the Navigation Drawer programmatically in Kotlin?
You call drawerLayout.openDrawer(GravityCompat.START) to open the drawer from the start (left) side.
Click to reveal answer
beginner
What is the purpose of NavigationView inside a Navigation Drawer?
NavigationView holds the menu items shown inside the drawer. It provides a consistent style and handles item clicks.
Click to reveal answer
intermediate
How do you handle item selection in a Navigation Drawer?
Implement NavigationView.OnNavigationItemSelectedListener and override onNavigationItemSelected to respond when a user taps a menu item.
Click to reveal answer
Which layout is used to create a Navigation Drawer in Android?
ADrawerLayout
BLinearLayout
CRelativeLayout
DConstraintLayout
✗ Incorrect
DrawerLayout is the special layout that supports a sliding drawer panel.
What method opens the Navigation Drawer from the left side in Kotlin?
AdrawerLayout.openDrawer(GravityCompat.START)
BdrawerLayout.show()
CdrawerLayout.open()
DdrawerLayout.slideIn()
✗ Incorrect
openDrawer(GravityCompat.START) opens the drawer from the start (usually left) side.
Which component holds the menu items inside a Navigation Drawer?
AListView
BMenuLayout
CNavigationView
DDrawerMenu
✗ Incorrect
NavigationView is designed to display menu items inside the drawer.
How do you listen for menu item clicks in a Navigation Drawer?
The correct order is (Activity, DrawerLayout, Toolbar, openDescRes, closeDescRes).
Step 2: Verify code matches this order
val drawerToggle = ActionBarDrawerToggle(this, drawerLayout, toolbar, R.string.open, R.string.close)
drawerLayout.addDrawerListener(drawerToggle)
drawerToggle.syncState() matches the correct parameter order and calls addDrawerListener and syncState properly.
Final Answer:
val drawerToggle = ActionBarDrawerToggle(this, drawerLayout, toolbar, R.string.open, R.string.close)
drawerLayout.addDrawerListener(drawerToggle)
drawerToggle.syncState() -> Option C
Quick Check:
Correct constructor order = val drawerToggle = ActionBarDrawerToggle(this, drawerLayout, toolbar, R.string.open, R.string.close)
drawerLayout.addDrawerListener(drawerToggle)
drawerToggle.syncState() [OK]
Hint: Remember constructor order: Activity, DrawerLayout, Toolbar, open, close [OK]
Common Mistakes:
Swapping DrawerLayout and Toolbar parameters
Missing open/close string resource IDs
Not calling addDrawerListener or syncState
3. Given this Kotlin code snippet inside an Activity, what happens when the user taps the hamburger icon?
val drawerToggle = ActionBarDrawerToggle(this, drawerLayout, toolbar, R.string.open, R.string.close)
drawerLayout.addDrawerListener(drawerToggle)
drawerToggle.syncState()
medium
A. The toolbar title changes to 'open'
B. The app crashes due to missing listener
C. Nothing happens because syncState is missing
D. The navigation drawer slides in from the side
Solution
Step 1: Understand ActionBarDrawerToggle behavior
It links the hamburger icon to open/close the drawer when tapped.
Step 2: Check code completeness
Code adds drawerToggle as listener and calls syncState, so toggle works correctly.
Final Answer:
The navigation drawer slides in from the side -> Option D
4. What is the error in this Kotlin code for setting up a navigation drawer?
val drawerToggle = ActionBarDrawerToggle(this, drawerLayout, toolbar, R.string.open, R.string.close)
drawerToggle.syncState()
medium
A. Missing call to drawerLayout.addDrawerListener(drawerToggle)
B. Wrong order of parameters in ActionBarDrawerToggle
C. Missing call to setSupportActionBar(toolbar)
D. Missing string resources for open and close
Solution
Step 1: Review drawer toggle setup steps
After creating drawerToggle, you must add it as a listener to drawerLayout.
Step 2: Identify missing method call
The code calls syncState but does not call drawerLayout.addDrawerListener(drawerToggle), so toggle won't work.
Final Answer:
Missing call to drawerLayout.addDrawerListener(drawerToggle) -> Option A
Quick Check:
Must add drawerToggle as listener [OK]
Hint: Always add drawerToggle as drawer listener [OK]
Common Mistakes:
Forgetting addDrawerListener call
Mixing parameter order in constructor
Skipping setSupportActionBar(toolbar) setup
5. You want to add a navigation drawer with three menu items: Home, Profile, and Settings. Which approach correctly sets up the drawer menu and handles item clicks in Kotlin?
hard
A. Define menu in XML, set NavigationView's menu, then use setNavigationItemSelectedListener to handle clicks
B. Create menu items programmatically in Activity, then override onOptionsItemSelected for clicks
C. Use a RecyclerView inside DrawerLayout for menu, handle clicks with adapter listener
D. Add buttons inside DrawerLayout layout XML and set onClickListeners in Activity
Solution
Step 1: Understand standard navigation drawer menu setup
Menus are usually defined in XML and linked to NavigationView for easy management.
Step 2: Handle item clicks with setNavigationItemSelectedListener
This listener handles user taps on menu items properly.
Final Answer:
Define menu in XML, set NavigationView's menu, then use setNavigationItemSelectedListener to handle clicks -> Option A
Quick Check:
XML menu + listener = Define menu in XML, set NavigationView's menu, then use setNavigationItemSelectedListener to handle clicks [OK]
Hint: Use XML menu and NavigationView listener for drawer items [OK]
Common Mistakes:
Trying to handle drawer menu with onOptionsItemSelected
Using RecyclerView unnecessarily for simple menus
Placing buttons directly inside DrawerLayout instead of NavigationView
Recommended
Ready to prove it?
Pass the test and this pattern moves unknownstrongwhile earning +1 Grip toward your certificate.