Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to display Emoji in Jetpack Compose?

Unable to display emojis properly using Jetpack Compose.

Code

    Text(
        text = data.emoji.character,
        textAlign = TextAlign.Center,
        fontSize = 28.sp,
    )
Jetpack Compose text

When using Compose Text, I am facing compatibility issues.
Tofu and multiple emojis appear as explained here.

To fix this, I tried using AppCompatTextView in AndroidView.

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.

like image 983
Abhimanyu Avatar asked Oct 18 '25 11:10

Abhimanyu


1 Answers

I was able to find this issue, which is probably related to your Text problem. It's fixed in Compose 1.4.0.

As to AppCompatTextView, it has default semi-transparent text color. Setting any color with alpha 1f solves the problem:

AppCompatTextView(context).apply {
    setTextColor(Color.Black.toArgb())
    text = "🥰 hello"
    textSize = 28F
    textAlignment = View.TEXT_ALIGNMENT_CENTER
}
like image 78
Philip Dukhov Avatar answered Oct 20 '25 01:10

Philip Dukhov



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!