【发布时间】:2021-08-18 13:01:11
【问题描述】:
代码:
val focusManager = LocalFocusManager.current
var code by remember { mutableStateOf("") }
var money by remember { mutableStateOf("") }
Column() {
Row() {
TextField(
modifier = Modifier.wrapContentSize(),
value = code,
keyboardOptions = KeyboardOptions(
keyboardType = KeyboardType.Number,
imeAction = ImeAction.Done
),
keyboardActions = KeyboardActions(onDone = {
focusManager.clearFocus()
}),
singleLine = true,
label = { Text("Code") },
onValueChange = { pscCode ->
code = pscCode.filter { it.isDigit() }.take(16)
})
Button(modifier = Modifier.fillMaxWidth(),
onClick = {…}
)
{
Text("Save data")
}
}
Row() {
TextField(
modifier = Modifier.wrapContentSize(),
value = money,
singleLine = true,
keyboardOptions = KeyboardOptions(
keyboardType = KeyboardType.Number,
imeAction = ImeAction.Done
),
keyboardActions = KeyboardActions(onDone = {
focusManager.clearFocus()
}),
label = { Text("Money amount") },
onValueChange = { moneyAmount ->
money = moneyAmount
.trim()
.replace(",", ".")
.take(5)
})
Button(modifier = Modifier.fillMaxWidth(),
onClick = {…}
) {
Text("Clean data")
}
}
}
我一直在尝试将按钮的大小与 textFields 的大小相匹配,但我没有找到方法,我尝试测量 textBoxes 的高度(没有结果),有没有更好(并且有效)的方法填补这些空白? 在此先感谢:)
【问题讨论】:
标签: android kotlin layout android-jetpack android-jetpack-compose