[英]Android Emoji App Compat Text View not rendering some emojis such as 👁
I'm trying to use the Emoji App Compat Text View but I don't understand what I'm doing wrong on my implementation.我正在尝试使用Emoji App Compat Text View,但我不明白我在实现中做错了什么。
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:我正在尝试渲染这三个表情符号
👣👁👀
,它在 Android Q 上运行良好,但在 Android Lollipop 上不起作用,请看截图:
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?据我了解,使用 Emoji App Compat Text View 的想法是让表情符号集从 android API 21 及更高版本正常工作,所以请看看我的实现,是否有任何遗漏、错误或 Emoji App Compat文本视图不像我想的那样工作?
You can get the complete code here at github or read the main parts below:您可以在 github 上获取完整代码或阅读以下主要部分:
Application's onCreate, set up the EmojiCompat, I'm not using the bundled version:应用程序的onCreate,设置EmojiCompat,我没有使用捆绑版本:
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: Activity,只需设置布局,获取View并设置文本:
<?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"
}
Conclusion : By default, the text style will be used, unless these are followed by the U+FE0F variation selector.结论:默认情况下,将使用文本样式,除非后面跟着 U+FE0F 变体选择器。
This can be validated using the following method:这可以使用以下方法进行验证:
Case 1 : Return false on all Android versions.案例 1 :在所有 Android 版本上返回 false。
EmojiCompat.get().hasEmojiGlyph(String(charArrayOf('\uD83D', '\uDC41')))
Case 2 : Return true on Android API versions >=18案例 2 :在 Android API 版本 >=18 上返回 true
EmojiCompat.get().hasEmojiGlyph(String(charArrayOf('\uD83D', '\uDC41', 65039.toChar())))
Solution : .setUseEmojiAsDefaultStyle(true)解决方案: .setUseEmojiAsDefaultStyle(true)
class App : Application() {
override fun onCreate() {
super.onCreate()
AppCompatDelegate.setCompatVectorFromResourcesEnabled(true)
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)
.setUseEmojiAsDefaultStyle(true)
.registerInitCallback(object : EmojiCompat.InitCallback() {
override fun onInitialized() {
super.onInitialized()
Toast.makeText(this@App, "EmojiCompat was initialized", LENGTH_SHORT).show()
}
override fun onFailed(throwable: Throwable?) {
super.onFailed(throwable)
throw RuntimeException(throwable)
}
})
)
}
}
Tested on Android API 19:在 Android API 19 上测试:
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.