如何在 Jetpack Compose 中获取带有渐变边框的 OutlinedTextField?
我正在尝试获取一个带有渐变边框的 OutlinedTextField
,如下所示:
但我只能向轮廓添加单一颜色,
OutlinedTextField(
value = email,
onValueChange = {email = it},
label = { Text(text = "Email Address") },
modifier = Modifier
.fillMaxWidth(.8f)
.padding(4.dp),
colors = TextFieldDefaults.outlinedTextFieldColors(unfocusedBorderColor = Color.Green)
)
如果我使用 modifier
添加边框,则渐变将应用于边框,而不是轮廓:
Modifier.border(width = 1.dp, brush = gradient, shape = RoundedCornerShape(12.dp))
如何向轮廓添加渐变颜色?
I'm trying to get an OutlinedTextField
with gradient border like this one:
But I can add only a single color to the outline,
OutlinedTextField(
value = email,
onValueChange = {email = it},
label = { Text(text = "Email Address") },
modifier = Modifier
.fillMaxWidth(.8f)
.padding(4.dp),
colors = TextFieldDefaults.outlinedTextFieldColors(unfocusedBorderColor = Color.Green)
)
If I add a border with modifier
then the gradient is applied to the border, not to the outline:
Modifier.border(width = 1.dp, brush = gradient, shape = RoundedCornerShape(12.dp))
How can I add gradient color to the outline?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
到目前为止,我知道 OutlinedTextField 不支持渐变边框。但如果真的想在文本字段中使用渐变边框,您可以尝试 BasicTextField
这就是最终结果

you can learn more about basic text field by looking the sample
[BasicTextField Samples][2]
so far that i know OutlinedTextField does't support gradient border. But if really want to use gradient border in text field you can try BasicTextField
and this is the final result

you can learn more about basic text field by looking the sample
[BasicTextField Samples][2]