如何在文本输入后隐藏或禁用提示标签?
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 "")}
您可以使用
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 "")
}
)
结果是