Android textview some emoji not showing?

Viewed 3358

I have a text like this .

"Hello world \u{1F603}" .

"\u{1F603}" this text must shown like emoji but cannot shown in Textview or AppCompatTextview . Some emoji shown like heart but smile or angry not shown .

I have some many textview in my project . How do I solve this problem simplest way .

Thanks for any suggestion.

3 Answers

Emoji Compatibility from support library.

build.gradle

ext {
  version = '27.1.1'
}
dependencies {
    ...
    implementation  "com.android.support:support-emoji-bundled:$version"
} 

MyApplication

public class MyApplication  extends Application{

    @Override
    public void onCreate() {
        super.onCreate();
        EmojiCompat.init(new BundledEmojiCompatConfig(getApplicationContext()));
    }
}

Manifest.xml

<application
    android:allowBackup="true"
    android:icon="@mipmap/ic_launcher"
    android:label="@string/app_name"
    android:roundIcon="@mipmap/ic_launcher_round"
    android:supportsRtl="true"
    android:name=".MyApplication" // reference to my application for init needed.
    android:theme="@style/AppTheme">

  // other activities definition.. 
</application>

Set Emoji to my TextView or AppCompatTextview

    // Regular TextView without EmojiCompat support; you have to manually process the text
    final TextView regularTextView = findViewById(R.id.textview);
    EmojiCompat.get().registerInitCallback(new InitCallback(regularTextView));

InitCallback

private static class InitCallback extends EmojiCompat.InitCallback {

    private final WeakReference<TextView> mRegularTextViewRef;

    InitCallback(TextView regularTextView) {
        mRegularTextViewRef = new WeakReference<>(regularTextView);
    }

    @Override
    public void onInitialized() {
        final TextView regularTextView = mRegularTextViewRef.get();
        if (regularTextView != null) {
            final EmojiCompat compat = EmojiCompat.get();
            regularTextView.setText(compat.process("Neutral face \uD83D\uDE10"));
        }
    }

}
Related