首页 > 解决方案 > 如何在 Row 上添加 TextField?

问题描述

我无法在行上添加文本字段。我已经尝试过使用 row、flexrow、flowrow、stack、wrap 和 container。在列上它有效。

java.lang.IllegalArgumentException: minWidth 2147483647.ipx should be finite
at androidx.ui.core.Constraints.<init>(Constraints.kt:48)   
at androidx.ui.core.Constraints$Companion.tightConstraintsForWidth(Constraints.kt:72) 
at...

我想这样输出;

用户名:(文本字段)

标签: androidandroid-jetpack-compose

解决方案


试试下面的代码

MaterialTheme {
                val state = +state { " " }
                Padding(left = 16.dp, right = 16.dp) {
                    FlexRow(
                        crossAxisAlignment = CrossAxisAlignment.Center
                    ) {
                        inflexible {
                            Container() {
                                Text{
                                    Span(
                                        text = "Username: ",
                                        style = TextStyle(
                                            color = Color(0xFFFF0000),
                                            fontSize = 18.sp,
                                            fontWeight = FontWeight.W200,
                                            fontStyle = FontStyle.Normal
                                        )
                                    )
                                }
                            }
                        }
                        expanded(1f) {
                            TextField(value = state.value, onValueChange = { state.value = it })
                        }
                    }
                }
            }

输出:

在此处输入图像描述


推荐阅读