如何隐藏 OutlinedTextField 边框上的提示标签

问题描述 投票:0回答:1

如何在文本输入后隐藏或禁用提示标签?

OutlinedTextField(
            value = value,
            modifier = Modifier.fillMaxSize(),
            shape = RoundedCornerShape(8.dp),
            textStyle = TextStyle(fontSize = nFontSize),
            colors = TextFieldDefaults.outlinedTextFieldColors(
                textColor = Color.Black,
                focusedBorderColor = colorResource(id = R.color.inbox_company_red),
                cursorColor = Color.Black),
            //visualTransformation = VisualTransformation.None,
            label = {Text(text = if (value.isEmpty()) stringResource(id = R.string.name" else "")}

android android-jetpack-compose textfield hint
1个回答
0
投票

您可以使用

remember
功能隐藏,如下所示:

    var value by remember { mutableStateOf("") 

然后更新您的

@Composable
,如下所示:

OutlinedTextField(
        value = value,
        onValueChange = {
            value = it
        },
        modifier = Modifier.fillMaxSize(),
        shape = RoundedCornerShape(8.dp),
        textStyle = TextStyle(fontSize = 16.sp),
        colors = TextFieldDefaults.outlinedTextFieldColors(
            textColor = Color.Black,
            focusedBorderColor = Color.Red, // Change this to your desired color
            cursorColor = Color.Black
        ),
        label = {
            Text(text = if (value.isEmpty()) "Hint" else "")
        }
    )

结果是

© www.soinside.com 2019 - 2024. All rights reserved.