How to Create an Exposed Dropdown Menu in Jetpack Compose
Hey fellas! Take your cup of coffee ☕️ and let’s create an Exposed Dropdown Menu using Jetpack Compose 😎.

Code
We will create a gender dropdown menu so, let’s start by creating the GenderDropdownMenu composable and initialize the isExpanded and the gender variables.
@Composable
fun GenderDropdownMenu() {
var isExpanded by remember {
mutableStateOf(false)
}
var gender by remember {
mutableStateOf("")
}
}Now add the ExposedDropdownMenuBox. This enables us to anchor the dropdown box to the TextField that we will create in a moment.
ExposedDropdownMenuBox(
expanded = isExpanded,
onExpandedChange = { newValue ->
isExpanded = newValue
}
) { /*TODO*/ }In the ExposedDropdownMenuBox we will create a TextField that will be read-only otherwise, we won’t be able to trigger the dropdown menu when we click on it. Also, we will use the ExposedDropdownMenuDefaults that gives us an animated icon that shows when the dropdown is expanded and the default TextField colors.
TextField(
value = gender,
onValueChange = {},
readOnly = true,
trailingIcon = {
ExposedDropdownMenuDefaults.TrailingIcon(expanded = isExpanded)
},
placeholder = {
Text(text = "Please select your gender")
},
colors = ExposedDropdownMenuDefaults.textFieldColors(),
modifier = Modifier.menuAnchor()
)Below the TextField we will create the ExposedDropdownMenu which holds a list of DropdownMenuItem.
ExposedDropdownMenu(
expanded = isExpanded,
onDismissRequest = {
isExpanded = false
}
) {
DropdownMenuItem(
text = {
Text(text = "Male")
},
onClick = {
gender = "Male"
isExpanded = false
}
)
DropdownMenuItem(
text = {
Text(text = "Female")
},
onClick = {
gender = "Female"
isExpanded = false
}
)
DropdownMenuItem(
text = {
Text(text = "Other")
},
onClick = {
gender = "Other"
isExpanded = false
}
)
}
I hope this article helped in your development journey. Remember to stay updated on my latest content by following me and subscribing to the newsletter. Thank you for reading!
Stackademic
Thank you for reading until the end. Before you go:
- Please consider clapping and following the writer! 👏
- Follow us on Twitter(X), LinkedIn, and YouTube.
- Visit Stackademic.com to find out more about how we are democratizing free programming education around the world.





