如何在 Jetpack Compose 中显示 Emoji?
How to display Emoji in Jetpack Compose?
无法使用 Jetpack Compose 正确显示表情符号。
代码
Text(
text = data.emoji.character,
textAlign = TextAlign.Center,
fontSize = 28.sp,
)
使用 Compose Text
时,我遇到了兼容性问题。
豆腐和多个表情符号按说明显示 here。
为了解决这个问题,我尝试在 AndroidView
中使用 AppCompatTextView
。
代码
AndroidView(
factory = { context ->
AppCompatTextView(context).apply {
text = data.emoji.character
textSize = 28F
textAlignment = View.TEXT_ALIGNMENT_CENTER
}
},
)
显示表情符号没有任何兼容性问题,但表情符号淡出。
我找到了 this issue,这可能与您的 Text
问题有关。
至于AppCompatTextView
,它有默认的semi-transparent文本颜色。使用 alpha 1f
设置任意颜色可解决问题:
AppCompatTextView(context).apply {
setTextColor(Color.Black.toArgb())
text = " hello"
textSize = 28F
textAlignment = View.TEXT_ALIGNMENT_CENTER
}
无法使用 Jetpack Compose 正确显示表情符号。
代码
Text(
text = data.emoji.character,
textAlign = TextAlign.Center,
fontSize = 28.sp,
)
使用 Compose Text
时,我遇到了兼容性问题。
豆腐和多个表情符号按说明显示 here。
为了解决这个问题,我尝试在 AndroidView
中使用 AppCompatTextView
。
代码
AndroidView(
factory = { context ->
AppCompatTextView(context).apply {
text = data.emoji.character
textSize = 28F
textAlignment = View.TEXT_ALIGNMENT_CENTER
}
},
)
显示表情符号没有任何兼容性问题,但表情符号淡出。
我找到了 this issue,这可能与您的 Text
问题有关。
至于AppCompatTextView
,它有默认的semi-transparent文本颜色。使用 alpha 1f
设置任意颜色可解决问题:
AppCompatTextView(context).apply {
setTextColor(Color.Black.toArgb())
text = " hello"
textSize = 28F
textAlignment = View.TEXT_ALIGNMENT_CENTER
}