1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55
| @Composable fun DropdownSample() { val isExpanded = remember { mutableStateOf(false) } val list = listOf("A", "B", "C", "D", "E", "F", "G") val disabledValue = "B" var selectedIndex = remember { mutableStateOf(0) } Box( modifier = Modifier .fillMaxSize() .wrapContentSize(Alignment.TopStart) ) { Text( text = list[selectedIndex.value], modifier = Modifier .fillMaxWidth() .height(30.dp) .padding(10.dp) .clickable { isExpanded.value = true } .background( Color.Black ), color = Color.White ) DropdownMenu( expanded = isExpanded.value, onDismissRequest = { isExpanded.value = false }, modifier = Modifier .fillMaxWidth() .background(Color.Red) ) { list.forEachIndexed { index, s -> DropdownMenuItem(onClick = { selectedIndex.value = index isExpanded.value = false } ) { val disaledText = if (disabledValue == s) { " (Disabled)" } else { "" } Text(text = "${s}${disaledText}") } } } } }
|