如何使用表情符号库在文本中添加表情符号?

How to can i add emoji in text using emoji library?

我想将表情符号添加到预定义的文本视图中。用户无需更改它。 我怎样才能做到这一点

"Hi there !"

在 TextView 中

在 Android 中使用表情符号库? 我需要使用表情符号库吗?

  • 检查这个库https://github.com/vanniktech/Emoji

    implementation 'com.vanniktech:emoji-ios:0.5.1'
    
  • 将此行添加到应用程序 class 内的 onCreate

    EmojiManager.install(new IosEmojiProvider()); // This line needs to be executed before any usage of EmojiTextView, EmojiEditText or EmojiButton.
    
  • 然后使用EmojiEditText & EmojiTextView

    <com.vanniktech.emoji.EmojiTextView
        android:id="@+id/emojiTV"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"/>
    

更新

  • 使用EmojiCompat

    • 打开您的应用程序的 build.gradle 文件。
    • 将支持库添加到依赖项部分。

      dependencies {
            ...
           compile "com.android.support:support-emoji:27.1.1"
      }
      
    • 在布局 XML 中使用 EmojiCompat 小部件。如果您使用的是 AppCompat,请参阅将 EmojiCompat 小部件与 AppCompat 部分结合使用。

      <android.support.text.emoji.widget.EmojiTextView
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"/>
      

更新 2

  • 对于预定义表情符号,您可以使用unicode emojis, as Navneet Krishna

你不需要图书馆。

Method 1

假设你有一个文本视图,然后试试这个

textView.setText(new String(Character.toChars(0x1F60A)));

其中 0x1F60A 是您的笑脸的 unicode

Alternate Method

strings.xml

中添加此资源

<string name="smiley_text">&#x1F60A;</string>

然后将其添加到文本视图中,如下所示

textview.setText(R.string.smiley_text);

试试这个:

int unicode = 0x1F60A;

可以与

一起使用
public String getEmojiByUnicode(int unicode){
return new String(Character.toChars(unicode));

}

因此 Textview 显示时没有 Drawable

引用link:http://apps.timwhitlock.info/emoji/tables/unicode