7

How to Add Smiley/Emojis in Edittext?

Any Source code is Available on Internet, if yes Please Give me Link.

Thanks in Advance.

Dipak Keshariya
  • 22,193
  • 18
  • 76
  • 128

2 Answers2

16

I am using below code for add Smiley/Emojis in edittext.

ImageGetter imageGetter = new ImageGetter() {
    public Drawable getDrawable(String source) {
        Drawable d = getResources().getDrawable(R.drawable.happy);
        d.setBounds(0, 0, d.getIntrinsicWidth(), d.getIntrinsicHeight());
        return d;
    }
};

cs = Html.fromHtml("<img src='" + getResources().getDrawable(R.drawable.happy) + "'/>", imageGetter, null);
edttxtemoji.setText(cs);
Dipak Keshariya
  • 22,193
  • 18
  • 76
  • 128
  • Hi Dipak, I have implement a textShortMessage for edit text so get the smiley code in android, i want to generate smiley image on the base of that obtain code in edit text but i can't get it. so can u please help any more please, i don't understand in your given code is that where i have to put this code. – amity Sep 06 '11 at 12:15
  • I have one doubt so reply me fast. – Dipak Keshariya Sep 07 '11 at 06:11
  • yes, if metter of your code its perfectly working. but i am working on something else, i am just using that concept only. – amity Sep 07 '11 at 08:32
  • let us [continue this discussion in chat](http://chat.stackoverflow.com/rooms/3231/discussion-between-amit-and-dipak-keshariya) – amity Sep 07 '11 at 08:33
  • How to get Smiley's from Edittext into String Format? if u know then help me. – Dipak Keshariya Sep 07 '11 at 09:43
1

Android may not support some special characters, but here is the tutorial anyways:

On a PC, I believe either Alt + 1 or Alt + 2 makes a smiley face.

This website provides an excellent tutorial for how to do alt codes, along with what alt code combination does what.

For a Mac, you can hold "Option + Command + T" down to open a list of special characters. From there, open the category "Miscellaneous." Your smiley is in there.

Is this what you are looking for? If not, just let me know :). When all else fails, you could just use an image of a smiley-face.

EDIT: I'm using a Mac. I opened TextEdit, followed my above tutorial for the Mac, generated a smiley face, cut the smiley face, and pasted it into the Java code. It worked for me. If it's not working for you, try copying this:

EditText mEditText = null;
mEditText.setText("☺");

EDIT 2: I thought Martin was looking for just a smiley, not a window of Emoji's. Currently, there is no source code to open this window - only a separate app that does this, which can be found at this link or this link.

Mxyk
  • 10,678
  • 16
  • 57
  • 76
  • Hello Mike Gates, how to help this link to display smiley in android edit text? – Dipak Keshariya Aug 25 '11 at 12:07
  • I'm sorry, I don't understand _exactly_ what you're looking for. If you want a smiley to appear in Android's `EditText`, couldn't you just follow the little tutorial in the answer I provided you and just put the smiley in the text field? – Mxyk Aug 25 '11 at 12:10
  • I'm assuming that Android doesn't support a smiley face as a special character. Try some of the other alt codes in the link I provided to you. Do any of those work? – Mxyk Aug 25 '11 at 12:15
  • Take a look at the edit I just added to the bottom of my response. Try doing that. If you have a PC, just use Notepad instead of TextEdit. – Mxyk Aug 25 '11 at 12:20
  • Not Work & second thing is android support a smiley face. any other code is used for smiley face? – Dipak Keshariya Aug 25 '11 at 12:21
  • I did a little research in the mean time, and I couldn't find any other way to generate a smiley - that is, your only two options are with alt codes or opening a special character list to choose from. – Mxyk Aug 25 '11 at 12:26
  • Maybe this is your problem - are you trying to use the numbers above your keys (the numbers on the top of your keyboard), or are you using the key pad (the one that looks like a phone pad)? To use alt codes, as far as I know, you must use the keypad. – Mxyk Aug 25 '11 at 12:27
  • if android support smiley face then give link of application in which smiley is in EditText – Niranj Patel Aug 25 '11 at 12:27
  • I added code to my response. Try copying it and see if that works for you. – Mxyk Aug 25 '11 at 12:30
  • Your Added Code is not Working, & following is link for smiley supported application. https://market.android.com/details?id=com.pansi.msg.plugin.emoji&feature=search_result – Dipak Keshariya Aug 25 '11 at 12:39
  • My code works if you add `import android.widget.EditText;`. I thought you were just looking for a way to add a simple smiley to an application, not a whole window of Emojis. I did some research, and I have to say that from what I've seen, there is an app that allows you to add Emojis (like in the link you provided), but I don't think there is any source code you can use to add them to an app. – Mxyk Aug 25 '11 at 12:52
  • video and screenshot of that app is dofferent..i didnt find any simley in video – Niranj Patel Aug 25 '11 at 12:56