如何更改android compose TextFeild 的内容填充?

时间:2021-01-27 05:44:37

标签: android kotlin android-jetpack-compose

它的填充太大了!我可以删除它们吗?

TextField(
            value = text,
            textStyle = TextStyle(
                color = Color.Red,
                textDecoration = TextDecoration.None
            ),
            onValueChange = {
                text = it
            },
            placeholder = {
                Text(text = "请输入设备序列号", color = Color.Gray)
            },
            singleLine = true,
            activeColor = Color.Yellow,
            modifier = Modifier.padding(1.dp),
            backgroundColor = Color.Transparent
        )

这是我的代码。请帮助我!

1 个答案:

答案 0 :(得分:0)

您可以使用 BasicTextField 来控制它。

            var value by rememberSaveable { mutableStateOf("") }

            BasicTextField(

                cursorBrush = SolidColor(Color.White),
                value = value,
                onValueChange = { value = it },
                textStyle = TextStyle(color = Color.White),
                decorationBox = { innerTextField ->

                    Row(modifier = Modifier.fillMaxWidth()) {
                        if (value.isEmpty()) {
                            Text(text = "Placeholder", color = Color.White)
                        }
                    }

                    innerTextField()
                }
            )