Jetpack Compose imageVector:如何使用来自 google 字体的社交矢量

Jetpack Compose imageVector : how do I able to use the Social vector from google fonts

我尝试按照Google字体的提示导入Google字体提供的图标,但是发现无法将蛋糕的图标导入到我的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 文件并在使用之前将其作为矢量资源导入到可绘制对象中,
  2. 如果您已经导入它,您应该使用 Icon(),而不是 Image(),而不是 imageVector,只需使用“painterResource(R.drawable.cake)”(当然,如果您将资产命名为“蛋糕” “
@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()
                }
            )
        }
    )
}