我尝试过使用
OutlinedTextField
或简单的TextField
,但我发现填充太大。无论我做什么,它都不会缩小。
所以我使用
BasicTextField
和较小的填充,如下所示:
BasicTextField(
modifier = modifier,
value = value,
keyboardActions = keyboardActions,
keyboardOptions = keyboardOptions,
onValueChange = onValueChange,
textStyle = textStyle,
decorationBox = { innerTextField ->
if (value.isEmpty()) placeholder()
innerTextField()
}
)
但问题是,当用户设置深色背景时,光标颜色保持黑色。我修改了文本颜色,使其可读,但光标颜色仍然是黑色。
选择颜色和光标颜色因此不可见。
有什么办法可以让它可见吗?我现在使用的是 Material 1.7.2。
谢谢你
我建议不要硬编码颜色;相反,允许
theme.kt
根据应用程序的深色或浅色模式管理颜色。
因此,在
colors
中定义您的配色方案,而不是对颜色值进行硬编码。
下面是一个例子: 这段代码来自我自己的代码;我希望它有帮助-
OutlinedTextField(
value = userGuess,
singleLine = true,
shape = shapes.large,
modifier = Modifier.fillMaxWidth(),
colors =
TextFieldDefaults.colors(
focusedContainerColor = Color.Transparent,
focusedTextColor = colorScheme.primary,
unfocusedContainerColor = Color.Transparent,
disabledContainerColor = Color.Transparent,
focusedIndicatorColor = colorScheme.primary,
unfocusedIndicatorColor = colorScheme.onSurface,
focusedLabelColor = colorScheme.primary,
unfocusedLabelColor = colorScheme.onSurface,
cursorColor = colorScheme.primary, // You can customize the cursor color here
)