将可组合文本字段的背景颜色设置为白色。 Android Jetpack 撰写

问题描述 投票:0回答:1

我有一个

OutlinedTextField
,我希望它有白色背景,但只有文本字段。问题是,当我添加
modifier = Modifier.background(color = AppWhite)
时,不仅文本字段是白色的,而且它周围的内容也是白色的(参见第一张附图),并且当我删除修改器时,所有内容都是绿色的(如第二张图片)。 这是我的可组合项:

           Row(
                modifier = Modifier.fillMaxWidth(),
                verticalAlignment = Alignment.CenterVertically,
                horizontalArrangement = Arrangement.Center
            ) {
                OutlinedTextField(
                    shape = RoundedCornerShape(20.dp),
                    modifier = Modifier.background(color = AppWhite),
                    value = searchText,
                    onValueChange = { searchText = it },
                    label = {
                        Text(stringResource(R.string.searchHint))
                    },
                    .
                    .
                    .
                Image(
                    modifier = Modifier.padding(top = 8.dp),
                    painter = painterResource(R.drawable.isotype_white),
                    contentDescription = null
                )

如何仅将 TextField 的背景设置为白色,而外面没有多余的白色??

enter image description here

android kotlin android-studio android-jetpack-compose android-compose-textfield
1个回答
0
投票

您可以使用

colors
参数为您的
OutlinedTextField
容器设置
colors
,如下所示:

OutlinedTextField(
    shape = RoundedCornerShape(20.dp),
    value = searchText,
    onValueChange = { searchText = it },
    label = {
        Text(stringResource(R.string.searchHint))
    },
    colors = OutlinedTextFieldDefaults.colors( 
        unfocusedContainerColor = Color.White,
        focusedContainerColor = Color.White
    )  
)
 
© www.soinside.com 2019 - 2024. All rights reserved.