Emoji Compatibility in Android

The EmojiCompat support library aims to keep Android devices up to date with the latest emoji. It prevents your app from showing missing emoji characters in the form of ☐, which indicates that your device does not have a font to display the text. By using the EmojiCompat support library, your app users do not need to wait for Android OS updates to get the latest emoji.

To implement latest emojis in your application, follow this tutorial.

First, import libraries in your dependencies:

build.gradle(Module:app)
implementation 'com.android.support:support-emoji-bundled:26.1.0'

Next, create layout for MainActivity and note what kind of widgets do we use:

activity_main.xml
<?xml version="1.0" encoding="utf-8"?>
<android.support.constraint.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    xmlns:tools="http://schemas.android.com/tools"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    tools:context="com.notifications.youtube.azem.virtuoozatutorials.MainActivity">

    <LinearLayout
        android:orientation="vertical"
        android:layout_width="match_parent"
        android:layout_height="match_parent">

        <android.support.text.emoji.widget.EmojiEditText
            android:id="@+id/edit_text"
            android:hint="Message..."
            android:layout_marginTop="30dp"
            android:layout_width="match_parent"
            android:layout_height="wrap_content" />

        <android.support.text.emoji.widget.EmojiTextView
            android:id="@+id/text_view"
            android:layout_marginTop="30dp"
            android:layout_width="match_parent"
            android:layout_height="wrap_content" />

        <Button
            android:id="@+id/btn_send"
            android:text="SEND"
            android:layout_marginTop="30dp"
            android:layout_width="match_parent"
            android:layout_height="wrap_content" />


    </LinearLayout>


</android.support.constraint.ConstraintLayout>

And now, in MainActivity, instantiate those widgets:

MainActivity.class
package com.notifications.youtube.azem.virtuoozatutorials;

import android.support.text.emoji.EmojiCompat;
import android.support.text.emoji.bundled.BundledEmojiCompatConfig;
import android.support.text.emoji.widget.EmojiEditText;
import android.support.text.emoji.widget.EmojiTextView;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;


public class MainActivity extends AppCompatActivity {

    EmojiEditText editText;
    EmojiTextView textView;
    Button send;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        EmojiCompat.Config config= new BundledEmojiCompatConfig(this);
        EmojiCompat.init(config);
        setContentView(R.layout.activity_main);

        editText= (EmojiEditText)findViewById(R.id.edit_text);
        textView= (EmojiTextView)findViewById(R.id.text_view);
        send= (Button)findViewById(R.id.btn_send);
        editText.setText("");

        send.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                if(!editText.getText().equals("")){
                    textView.setText(editText.getText().toString());
                }
            }
        });


    }
}
Share with your friends