I'm trying to use the Emoji App Compat Text View but I don't understand what I'm doing wrong on my implementation.
I'm trying to render these three emojis 👣👁👀
, it works fine on Android Q, but it is not working on Android Lollipop, take a look at the screenshots:
As far as I understood the idea of using the Emoji App Compat Text View is to get the emoji set working fine from android API 21 and later, so please take a look at my implementation, is there anything missing, wrong or maybe Emoji App Compat Text View does not work as I thought?
You can get the complete code here at github or read the main parts below:
Application's onCreate, set up the EmojiCompat, I'm not using the bundled version:
EmojiCompat.init(
FontRequestEmojiCompatConfig(
this,
FontRequest(
"com.google.android.gms.fonts",
"com.google.android.gms",
"Noto Color Emoji Compat",
R.array.com_google_android_gms_fonts_certs
)
).setReplaceAll(true)
// I did remove the callback for brevity, but I got the `onInitialized` called.
)
Activity, just set the layout, get the View and set the text:
<?xml version="1.0" encoding="utf-8"?>
<androidx.constraintlayout.widget.ConstraintLayout
…
<androidx.emoji.widget.EmojiAppCompatTextView
android:id="@+id/text_view"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textSize="60sp"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintLeft_toLeftOf="parent"
app:layout_constraintRight_toRightOf="parent"
app:layout_constraintTop_toTopOf="parent" />
…
</androidx.constraintlayout.widget.ConstraintLayout>
class MainActivity : AppCompatActivity() {
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
setContentView(R.layout.activity_main)
findViewById<EmojiAppCompatTextView>(R.id.text_view).text = getString(R.string.three_emojis)
}
}
Strings
<string name="three_emojis">👣👁👀</string>
gradle
plugins {
id "com.android.application"
id "kotlin-android"
}
android {
compileSdkVersion 29
buildToolsVersion "30.0.2"
…
defaultConfig {
minSdkVersion 21
targetSdkVersion 29
…
}
…
}
dependencies {
implementation "androidx.emoji:emoji-appcompat:1.1.0"
implementation "androidx.emoji:emoji:1.1.0"
implementation "org.jetbrains.kotlin:kotlin-stdlib:$kotlin_version"
implementation "androidx.appcompat:appcompat:1.2.0"
implementation "androidx.constraintlayout:constraintlayout:2.0.4"
implementation "androidx.core:core-ktx:1.3.2"
implementation "com.google.android.material:material:1.2.1"
}
kotlinc-jvm
and"👁"=="👁"
, left is the original and right came from emojipedia, the result wasres1: kotlin.Boolean = true
. – Tallyman65039
character, it is theVariation selector-16
and according to Wikipedia VS15 and VS16 are reserved to request that a character should be displayed as text or as an emoji respectively. So to test it, I did run.text = String(charArrayOf('\uD83D', '\uDC41'))
and I did not get the emoji. running.text = String(charArrayOf('\uD83D', '\uDC41', 65039.toChar()))
I get the emoji. and running VS15.text = String(charArrayOf('\uD83D', '\uDC41', 65038.toChar()))
I get no emoji as expected. – Tallyman