Android EmojiCompat Library

Emojis, Emojis, Emojis. If you’re working on a chat app or creating an app in which user has to communicate with other users, this blog is for you. New Emojis are constantly being added to the Unicode standard. Now, it’s important that all users will be able to see the new Emojis even if they are stuck on previous Android Versions.

If you still see an empty box☒ with the cross, it means that the app you’re using probably not using the EmojiCompatLibrary.

Luckily for an Android developer, Google has released a new library knows as EmojiCompat. With EmojiCompat support library your app user does not need to wait for Android OS update to get the latest emoji. The EmojiCompat support library compatible with devices running Android 4.4 (API level 19) or higher.

How does EmojiCompat work under the hood..?

Well, the library takes Unicode in the form of CharSequence that is representing an Emoji if the given code did not recognize on the device, then the library replaces Emoji character with the EmojiSpan. EmojiCompat performs some internal calls, once it completes it renders the Emoji Glyph


Base Span class for the emoji replacement. When an emoji is found and needs to be replaced in a CharSquence, an instance of this class is added to CharSequence. This is the process which ensures that the device will display the given Emoji. 

EmojiCompat Widgets

  1. EmojiCompatTextView
  2. EmojiCompatEditText
  3. EmojiCompatButton

Android App Setup

First, add the support library to the dependency section.

implementation ''

EmojiCompat builds on the downloadable fonts mechanism, to make sure that you always have the latest Emojis available. So, if you want the Emojis fonts to be downloadable when your app is installed from play store. Add the below metadata in your Manifest.xml file.

    android:value="Noto Color Emoji Compat" />

Before being used the EmojiCompat library needs one-time Asynchronous setup. Google developer recommend this in your Launch Activity or CustomApplication class. The following shows how to setup EmojiCompat.

val fontRequest =
                "Noto Color Emoji Compat",
val config = FontRequestEmojiCompatConfig(this, fontRequest)

When using the downloadable fonts configuration create your FontRequest and FontRequestEmojiCompatConfig object.


FontRequest class provide the font provider authority, the font provider package and a list of set hashes for the certificate. For more information about FontRequest see this link.

Configuration Options

  • setReplaceAll: When set to true replace all emojis with EmojiSpans. By default, EmojiCompat tries it’s best to understand if the system can render an emoji and does not replace those emojis.
  • setEmojiSpanIndicatorEnabled: Indicates whether EmojiCompat has replaces an emoji with EmojiSpan. This method is mainly used for debugging purpose.
  • setEmojiSpanIndicatorColor: Color used for indicating EmojiSpan. The default color is Green.
  •  registerCallback: If you want to get notified when your app is ready to start using EmojiCompat use EmojiCompat.InitCallback.

Tip: It’s a good approach that you initialize the EmojiCompat in the background thread. For this, you can use Observable, Kotlin Co-Routine or IntentService.

Using EmojiCompat Widgets

After the successful initialization of EmojiCompat, you can use the Emoji Widgets in the xml file or you can create Custom Widgets by extending Emoji Widgets. 

The following shows how we can add EmojiCompat widgets in the xml file.




Now let’s see how we can create EmojiTextView with a custom view. EmojiCompat provides the EmojiTextViewHelper class for custom widget emoji support. The following shows how we can create custom EmojiTextView.

class CustomEmojiTextView(context: Context) : AppCompatTextView(context) {

    init {

    override fun setFilters(filters: Array<out InputFilter>?) {

    override fun setAllCaps(allCaps: Boolean) {

    private fun getEmojiTextViewHelper() = EmojiTextViewHelper(this)

    // Remaining stuff......

Like EmojiTextViewHelper EmojiCompat provides EmojiEditTextHelper for creating custom EditText with emoji support. The following shows how we can create custom EmojiEditText.

class CustomEmojiEditText(context: Context) : AppCompatEditText(context) {

    init {

    override fun setKeyListener(input: KeyListener?) {

    override fun onCreateInputConnection(outAttrs: EditorInfo?): InputConnection {
        val inoutConnection = super.onCreateInputConnection(outAttrs)
        return outAttrs?.let { getEmojiEditTextHelper().onCreateInputConnection(inoutConnection, it) }!!

    private fun getEmojiEditTextHelper() = EmojiEditTextHelper(this)

EmojiCompat with AppCompat

If you’re using AppCompat classes, then you can use EmojiCompat widgets that extend from AppCompat widgets. For this, you’ve to add another dependency.

implementation ''

Use EmojiCompat AppCompat widgets in xml.




Using EmojiCompat without widgets

If you’re not using EmojiCompat widgets in the xml file. You can still use EmojiCompat library to convert CharSequence into spanned instances with EmojiSpane. The EmojiCompat class provides a “process” method which returns a CharSequence. 

The following shows how we can use it.

val charSequence = EmojiCompat.get().process("Normal TextView \uD83D\uDE48\uD83D\uDE49\uD83D\uDE4A")
normalTextView.text = charSequence

Bundled Fonts

If you can not use downloadable fonts then you can bundle the emoji fonts in APK file. For this, you have to add a new dependency to a build. gradle file.

implementation ''

Now we simply need to init our EmojiCompat with BundledEmojiCompatConfig. Loading the size of fonts is multiple MegaBytes, so do run this on a background thread instead of the main thread.

val config = new BundledEmojiCompatConfig(context : this)

Note: By adding bundled fonts your APK size will increase.

So, you guy’s see that how we can add EmojiCompat library with very much less code and also it has backward compatibility as well. I hope this blog gives you a good understanding of EmojiCompat. If you guys have any question please do comment below.

Thank you for being here and keep reading…


Please enter your comment!
Please enter your name here