[英]How to display Emoji in Jetpack Compose?
Unable to display emojis properly using Jetpack Compose.无法使用 Jetpack Compose 正确显示表情符号。
Code代码
Text(
text = data.emoji.character,
textAlign = TextAlign.Center,
fontSize = 28.sp,
)
When using Compose Text
, I am facing compatibility issues.使用 Compose
Text
时,我遇到了兼容性问题。
Tofu and multiple emojis appear as explained here .豆腐和多个表情符号显示为解释here 。
To fix this, I tried using AppCompatTextView
in AndroidView
.为了解决这个问题,我尝试在
AndroidView
中使用AppCompatTextView
。
Code代码
AndroidView(
factory = { context ->
AppCompatTextView(context).apply {
text = data.emoji.character
textSize = 28F
textAlignment = View.TEXT_ALIGNMENT_CENTER
}
},
)
It displays the emojis without any compatibility issue, but the emojis are faded out.它显示表情符号没有任何兼容性问题,但表情符号淡出。
I was able to find this issue , which is probably related to your Text
problem.我能够找到这个问题,这可能与您的
Text
问题有关。
As to AppCompatTextView
, it has default semi-transparent text color.至于
AppCompatTextView
,它具有默认的半透明文本颜色。 Setting any color with alpha 1f
solves the problem:使用 alpha
1f
设置任何颜色都可以解决问题:
AppCompatTextView(context).apply {
setTextColor(Color.Black.toArgb())
text = "🥰 hello"
textSize = 28F
textAlignment = View.TEXT_ALIGNMENT_CENTER
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.