如何在jetpack compose BasicTextField中设置边框颜色?

发布于 2025-01-14 09:22:11 字数 840 浏览 4 评论 0原文

我使用 package androidx.compose.foundation.text 中的 BasicTextField ,它具有默认的灰色字段颜色,如下所示: 输入图片这里的描述

我不想要这个灰色突出显示,因此我想将backgroundColor完全设置为黑色:

BasicTextField(
    modifier = Modifier
        .background(Color.Black)
)

但这确实只部分生效,如此处所示 输入图片这里的描述

有一个边框仍然是灰色的。

保留边框尺寸是可以的,但我想要像这里一样有一个完整的黑色背景 输入图片此处描述

我该如何管理?

编辑:我尝试使用 color = Color.Black 添加 border() 修饰符 - 但徒劳。

I use BasicTextField from package androidx.compose.foundation.text and it has a default grey field color as visible here:
enter image description here

I do not want this grey highlight, therefore I want to set the backgroundColor completely to black:

BasicTextField(
    modifier = Modifier
        .background(Color.Black)
)

But this does take effect only partially as visible here
enter image description here

There is a border still having grey color.

It is ok to keep the border dimensions, but I would like to have a complete black background as here
enter image description here

How can I manage this?

Edit: I tried to add a border() modifier with color = Color.Black - in vain.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

相思碎 2025-01-21 09:22:11

我不确定您的可组合项的代码,请尝试:

@Composable
fun Simple() {
    var v by remember { mutableStateOf("Text") }
    Row(Modifier.background(Color.Black).padding(16.dp),verticalAlignment = Alignment.CenterVertically) {
        Icon(Icons.Filled.ArrowBack, contentDescription = "back",tint = Color.White)
        BasicTextField(
            v, { v = it },
            Modifier
                .weight(1f)
                .padding(start = 13.dp),
            textStyle = TextStyle(Color.White, 13.sp),
            singleLine = true
        )
    }
}

I'm not sure about the code of your Composable,please try:

@Composable
fun Simple() {
    var v by remember { mutableStateOf("Text") }
    Row(Modifier.background(Color.Black).padding(16.dp),verticalAlignment = Alignment.CenterVertically) {
        Icon(Icons.Filled.ArrowBack, contentDescription = "back",tint = Color.White)
        BasicTextField(
            v, { v = it },
            Modifier
                .weight(1f)
                .padding(start = 13.dp),
            textStyle = TextStyle(Color.White, 13.sp),
            singleLine = true
        )
    }
}
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文