Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Dropdown Button/Wheel Picker/Spinner in Jetpack Compose

Is there any standard implementation in Jetpack Compose for visual component like Spinner/Wheel Picker or Dropdown Button?

like image 373
Solvek Avatar asked Jun 04 '21 18:06

Solvek


People also ask

What is recomposition in jetpack compose?

Recomposition is when Jetpack Compose re-executes the composables that may have changed in response to state changes, and then updates the Composition to reflect any changes. A Composition can only be produced by an initial composition and updated by recomposition.

Is jetpack easier to compose?

Jetpack Compose is a modern declarative UI Toolkit for Android. Compose makes it easier to write and maintain your app UI by providing a declarative API that allows you to render your app UI without imperatively mutating frontend views.

Is jetpack compose stable now?

Today, we're releasing version 1.2 of Jetpack Compose, Android's modern, native UI toolkit, continuing to build out our roadmap.

Does jetpack compose use XML?

Jetpack Compose is a modern toolkit that allows us to build our screens in a declarative approach writing less code. Android UI Development is now more powerful and more decoupled. Before Jetpack Compose, we were using XML layouts to build the native UI.


Video Answer


1 Answers

You can use a Button with a DropdownMenu.
Something like:

var expanded by remember { mutableStateOf(false) }
val suggestions = listOf("Item1", "Item2", "Item3")

Button(onClick = { expanded = !expanded }){
    Text ("DropDown")
    Icon(
        imageVector = Icons.Filled.ArrowDropDown,
        contentDescription = null,
    )
}
DropdownMenu(
    expanded = expanded,
    onDismissRequest = { expanded = false },
) {
    suggestions.forEach { label ->
        DropdownMenuItem(onClick = {
            expanded = false
            //do something ...
        }) {
            Text(text = label)
        }
    }
}

enter image description here enter image description here

like image 58
Gabriele Mariotti Avatar answered Oct 21 '22 12:10

Gabriele Mariotti