【问题标题】:Emoji not dynamically appearing correctly in button表情符号未在按钮中动态正确显示
【发布时间】:2019-11-13 05:00:26
【问题描述】:

我正在尝试在我的 Button 中的文本旁边添加一个表情符号字符,但由于某种原因,它仅以纯白色显示,并且没有作为官方 Android 表情符号字符出现。有谁知道出了什么问题以及如何解决这个问题?

注意:我不想使用任何 Drawables。

预期外观

目前的样子

XML 布局

<?xml version="1.0" encoding="utf-8"?>
<androidx.constraintlayout.widget.ConstraintLayout
        xmlns:android="http://schemas.android.com/apk/res/android"
        xmlns:tools="http://schemas.android.com/tools"
        xmlns:app="http://schemas.android.com/apk/res-auto"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        tools:context=".MainActivity">

    <Button
            android:text="Button"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:id="@+id/button" 
            app:layout_constraintStart_toStartOf="parent"
            app:layout_constraintEnd_toEndOf="parent"
            app:layout_constraintTop_toTopOf="parent"
            app:layout_constraintBottom_toBottomOf="parent"/>
</androidx.constraintlayout.widget.ConstraintLayout>

import android.os.Bundle
import android.widget.Button
import androidx.appcompat.app.AppCompatActivity

class MainActivity : AppCompatActivity() {

    override fun onCreate(savedInstanceState: Bundle?) {
        super.onCreate(savedInstanceState)
        setContentView(R.layout.activity_main)
        my_button.text = "\u2642 Hello World"
    }
}

【问题讨论】:

标签: android kotlin unicode android-button emoji


【解决方案1】:

尝试使用表情符号的完全限定形式(表情符号样式而不是文本样式),方法是附加:U+FE0F VARIATION SELECTOR-16

mButton.text = "\u2642\uFE0F Hello World"

emoji-test.txt

# subgroup: gender
2640 FE0F                                  ; fully-qualified     # ♀️ female sign
2640                                       ; unqualified         # ♀ female sign
2642 FE0F                                  ; fully-qualified     # ♂️ male sign
2642                                       ; unqualified         # ♂ male sign

emoji-variation-sequences.txt

2640 FE0E  ; text style;  # (1.1) FEMALE SIGN
2640 FE0F  ; emoji style; # (1.1) FEMALE SIGN
2642 FE0E  ; text style;  # (1.1) MALE SIGN
2642 FE0F  ; emoji style; # (1.1) MALE SIGN

【讨论】:

    【解决方案2】:

    您可以设置按钮视图的样式, 比如改变视线的重心,

    android:gravity="center"
    

    或 安卓:layout_gravity="center" 这可以将视图设置为方面 希望对你有帮助!!

    【讨论】:

      猜你喜欢
      • 2016-10-05
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多