Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

I want to add an emoji to a predefined text view. User no need to change that. How can i achieve this

"Hi there 😀!"

in TextView

in Android using emoji library ? Do i need to use emoji library ?

like image 535
user5444140 Avatar asked Jan 20 '26 14:01

user5444140


2 Answers

You don't need a library for this.

Method 1

Suppose you have a textview, then try this

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

where 0x1F60A is the unicode for your smiley

Alternate Method

add this resource in strings.xml

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

then add it to textview like below

textview.setText(R.string.smiley_text);
like image 187
Navneet Krishna Avatar answered Jan 23 '26 03:01

Navneet Krishna


  • Check this library https://github.com/vanniktech/Emoji

    implementation 'com.vanniktech:emoji-ios:0.5.1'
    
  • Add this line to onCreate inside Application class.

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

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

Update

  • Use EmojiCompat

    • Open the build.gradle file of your application.
    • Add the support library to the dependencies section.

      dependencies {
            ...
           compile "com.android.support:support-emoji:27.1.1"
      }
      
    • Use EmojiCompat widgets in layout XMLs. If you are using AppCompat, refer to the Using EmojiCompat widgets with AppCompat section.

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

Update 2

  • For predefined emojis you can use unicode emojis, as Navneet Krishna answer.
like image 20
Khaled Lela Avatar answered Jan 23 '26 03:01

Khaled Lela



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!