gpt4 book ai didi

android - jetpack compose shadow 奇怪的行为

转载 作者:行者123 更新时间:2023-12-05 04:21:56 26 4
gpt4 key购买 nike

我正在尝试构建一个带阴影的文本字段

这是我取得的结果。

enter image description here

但是如果你放大图片你会看到白色文本框下有一些矩形背景(请看文本框外面的角,有背景)

我怎样才能删除那个背景?

@Composable
fun MyTextField() {

var text by remember {
mutableStateOf("")
}

Box(
modifier = Modifier
.padding(15.dp)
.shadow(5.dp)
.background(color = Color.White, shape = RoundedCornerShape(10.dp))
.fillMaxWidth()
.height(50.dp),
contentAlignment = Alignment.Center,
) {
TextField(
value = text,
onValueChange = { text = it },
label = { Text(text = "Phone number", color = Color.Gray, fontSize = 14.sp) },
modifier = Modifier
.fillMaxSize()
.background(color = Color.Transparent, shape = RoundedCornerShape(10.dp)),

colors = TextFieldDefaults.textFieldColors(
backgroundColor = Color.Transparent,
focusedIndicatorColor = Color.Transparent,
unfocusedIndicatorColor = Color.Transparent
),
)
}


}

最佳答案

默认情况下,shadow 修饰符使用 RectangleShape,这是您出现问题的原因:

enter image description here

相同的形状应用于阴影背景修饰符:

val shape = RoundedCornerShape(10.dp)

Box(
modifier = Modifier
.padding(15.dp)
.shadow(
elevation = 5.dp,
shape = shape
)
.background(color = Color.White, shape = shape)
.fillMaxWidth()
.height(50.dp),

contentAlignment = Alignment.Center,
)

enter image description here

关于android - jetpack compose shadow 奇怪的行为,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/74126225/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com