【问题标题】:Forms with Kotlin : How can I add a drop down menu in a form in Kotlin [duplicate]Kotlin 的表单:如何在 Kotlin 的表单中添加下拉菜单 [重复]
【发布时间】:2022-01-21 05:25:14
【问题描述】:

我从 Kotlin 开始,我想知道如何在 Kotlin 中制作带有下拉菜单的表单。我做了这个,但看起来不太好。

代码:

                       var billingPeriodExpanded by remember { mutableStateOf(false) }

                    var selectedIndex by remember { mutableStateOf(0) }


                    OutlinedTextField(
                        value = billingPeriodItems[selectedIndex],
                        onValueChange = { selectedIndex = billingPeriodItems.indexOf(it) },
                        label = {
                            Column(modifier = Modifier.fillMaxSize()) {
                                ComposeMenu(

                                    menuItems = billingPeriodItems,
                                    menuExpandedState = billingPeriodExpanded,
                                    seletedIndex = selectedIndex,
                                    updateMenuExpandStatus = {
                                        billingPeriodExpanded = true
                                    },
                                    onDismissMenuView = {
                                        billingPeriodExpanded = false
                                    },
                                    onMenuItemclick = { index ->
                                        selectedIndex = index
                                        billingPeriodExpanded = false
                                    }
                                )
                            }
                        },

                        singleLine = true,
                        modifier = Modifier.fillMaxWidth(0.8f)
                    )

它看起来是这样的:

here you can see how the drop-down menu is over the field and not inside of it

你知道我该如何解决吗?

【问题讨论】:

    标签: android kotlin user-interface android-jetpack-compose


    【解决方案1】:

    无需重新发明轮子。 Compose 中已经有一个组件可以执行此操作:

    Stackoverflow - Exposed Dropdown Menu for Compose

    查看最新的代码示例:

    ExposedDropdownMenuTest.kt

    只要搜索函数:

    ExposedDropdownMenuForTest

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2022-01-22
      • 1970-01-01
      • 2011-05-14
      • 1970-01-01
      • 2023-03-21
      • 1970-01-01
      • 2021-03-17
      • 2019-07-22
      相关资源
      最近更新 更多