Android(kotlin) - JetPack Compose - DropdownMenu

하동혁 ·2023년 9월 1일
0

Android Jetpack Compose

목록 보기
26/30
post-thumbnail
post-custom-banner
  • DropdownMenu
		expanded: Boolean,
    onDismissRequest: () -> Unit,
    modifier: Modifier = Modifier,
    offset: DpOffset = DpOffset(0.dp, 0.dp),
    properties: PopupProperties = PopupProperties(focusable = true),
    content: @Composable ColumnScope.() -> Unit
  • DropdownMenuItem
		text: @Composable () -> Unit,
    onClick: () -> Unit,
    modifier: Modifier = Modifier,
    leadingIcon: @Composable (() -> Unit)? = null,
    trailingIcon: @Composable (() -> Unit)? = null,
    enabled: Boolean = true,
    colors: MenuItemColors = MenuDefaults.itemColors(),
    contentPadding: PaddingValues = MenuDefaults.DropdownMenuItemContentPadding,
    interactionSource: MutableInteractionSource = remember { MutableInteractionSource() 

실습

@Composable
fun DropdownMenuEx() {
    var expandStatus by remember { mutableStateOf(false) }
    var counter by remember { mutableStateOf(0) }

    Column {
        Button(onClick = {
            expandStatus = true // 버튼 클릭시 드롭다운 메뉴 열기 
        }) {
            Text(text = "DropdownMenu open")
        }

        Text(text = "Counter: $counter")
    }

    DropdownMenu(
        expanded = expandStatus,
        onDismissRequest = { // 사라질때 
            expandStatus = false
        }
    ) {
        // 메뉴 안에 들어갈 값들
        DropdownMenuItem(
            text = { Text(text = "plus")},
            onClick = {
                counter++
                expandStatus = false
            }
        )

        DropdownMenuItem(
            text = {Text(text = "minus")},
            onClick = {
                counter--
                expandStatus = false
            }
        )
    }
}

@Preview(showBackground = true)
@Composable
fun DropdownMenuPreview() {
    Compose_exampleTheme {
        DropdownMenuEx()
    }
}

post-custom-banner

0개의 댓글