gpt4 book ai didi

kotlin - Jetpack Compose 图像向量 : how do I able to use the Social vector from google fonts

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

我尝试按照Google Font的提示导入Google Font提供的图标,但是发现无法将蛋糕的图标导入到我的EditText中。你能看看发生了什么事吗?非常感谢!

@Composable
fun ShowTextField(context:Context){

var text by remember {
mutableStateOf("")
}
TextField(value = text ,
onValueChange = {text = it},text
label = { Text(text = "birthday")},
leadingIcon = @Composable{

Image(
imageVector = Icons.Filled.Cake,
contentDescription = "cake",
modifier = Modifier.clickable {
Toast.makeText(
context,
"Your Birthday:${text}",
Toast.LENGTH_SHORT
).show()
}
)
}
)
}

Cake Google Font

最佳答案

  1. 据我所知,在使用之前,您需要将其下载为 .svg 文件并作为矢量资源导入到 drawable 文件夹中,
  2. 导入它后,在您的代码中您应该使用 Icon(),而不是 Image(),而不是 imageVector,只需使用 painterResource(R.drawable.cake)

(当然,如果您将 Assets 命名为“蛋糕”;))

@Composable
fun ShowTextField(context:MainActivity){

var text by remember {
mutableStateOf("")
}

TextField(value = text,
onValueChange = {text = it},
label = { Text(text = "birthday")},
leadingIcon = @Composable{

Icon(
painterResource(R.drawable.cake),
contentDescription = "cake",
modifier = Modifier.clickable {
Toast.makeText(
context,
"Your Birthday:${text}",
Toast.LENGTH_SHORT
).show()
}
)
}
)

}

关于kotlin - Jetpack Compose 图像向量 : how do I able to use the Social vector from google fonts,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/70455460/

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