[英]How to change border width of a particular side only in jetpack compose?
[英]How change OutlineTextField border width in Android Jetpack Compose?
我的代码:
OutlinedTextField(
value = state.value,
onValueChange = { state.value = it },
modifier = Modifier.fillMaxWidth().padding(start = 30.dp, end = 30.dp),
label = { Text(text = "Something", fontSize = 14.sp) },
shape = RoundedCornerShape(12.dp),
)
我想增加边框宽度,以便支持 colors focusedBorderColor
和disabledBorderColor
。
您可以像这样更改 OutlinedTextField 边框
var hasFocus by remember { mutableStateOf(false) }
OutlinedTextField(
modifier = modifier
.border(
width = 1.dp,
color = if (hasFocus) Color.Red else Color.Unspecified
)
.onFocusChanged { focusState -> hasFocus = focusState.hasFocus },
colors = TextFieldDefaults.outlinedTextFieldColors(
focusedBorderColor = Color.Unspecified,
unfocusedBorderColor = Color.Unspecified
)
)
另一种解决方案是使用BaseTextField
而不是OutlinedTextField
轮廓边框在OutlinedTextField
定义为常量值。
private val IndicatorUnfocusedWidth = 1.dp
private val IndicatorFocusedWidth = 2.dp
没有直接的方法来覆盖这些值。
因此,如果您需要实现动态边框宽度,则必须创建完整的自定义 TextField Composable。
您可以复制粘贴OutlinedTextField.kt
和TextFieldImpl.kt
的完整代码,并根据需要修改它们以创建自定义可组合。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.