4

How can I insert emoji/smiley/emoticons in an input method editor (in soft keyboard) ? which method should I use for that purpose?

  1. To create a True type font ? (I think that the font comes in one color)
  2. To use SpannableStringBuilder and attatch the emoticons to the string in it?
  3. or another method?

NOTE : I'm not asking for code .. Just for the method.


Note :

I used the following function:

public CharSequence addSmileySpans(CharSequence text) {
    Bitmap bm = BitmapFactory.decodeResource(getResources(), R.drawable.smiley);
    SpannableStringBuilder builder = new SpannableStringBuilder(text);
    builder.setSpan(new ImageSpan(this,bm), 1,3,
                    Spannable.SPAN_EXCLUSIVE_EXCLUSIVE);
    return builder;
}

and I called it like this

getCurrentInputConnection().setCommitText(addSmileySpans("123"),1);

The result was printing the 123 in the editor without the smiley.

haggai_e
  • 4,689
  • 1
  • 24
  • 37
Android
  • 51
  • 6
  • 1
    The comment by @mernen at http://stackoverflow.com/questions/1538331/android-cant-figure-how-to-use-setimeactionlabel/1541161#1541161 seems to suggest that you can use `EditorInfo.inputType="textShortMessage"` to add emoticons to your IME. – haggai_e Oct 12 '11 at 11:20
  • This is already quite outdated, but I just confirmed what haggai_e said, with 'textShortMessage' it works. However, I tried my custom keyboard with Line, Messanger or Whatsapp, and there I cannot post my emoticons, apps like Kika Emoji Keyboard however can. So there bound to be another method... – Flo Nov 07 '15 at 03:14

0 Answers0