I am trying to have a button with an emoji character within the text string for that button. I know there is a way to do this in iOS, is there a way to do this in Android?
In Android, you use Spannable to display images inline with text (which is similar to the iOS 'NSAttributedString` concept, I believe).
This should work for TextView Button and EditText and there are many references / examples available, depending on your needs.
Check out the answer over here:
how set emoji by unicode in a textview?
You have to use unicodes unlike in iOS where you can add them directly
Related
I wanted to show Unicode in a text view in my android app. I searched for a solution but nothing really helped.
I wanted to do this programmatically in Kotlin as I want to concatenate it with the data that I fetch from Firestore.
First of all, check that font you use supports Unicode.
Then you can use Html.fromHtml as #Anshul advised but keep in mind that it is deprecated and you need to use Html.FROM_HTML_MODE_LEGACY as it was advised in Unicode characters not displayed in TextView.setText
You can parse unicode from html to string by using HTML library like
val bullet = "•"
print("this is bullet a ${Html.fromHtml(bullet)}")
I need library that highlight HTML, CSS and JavaScript code. And also User can edit the code.
It seems to be hard to implement, but here is a recipe to make it.
To highlight codes in various styles, you can use https://github.com/binaryfork/Spanny work. It is appliable to TextView or EditText, as the result of Spanny is a Spannable object.
And, to analyze a text file as a HTML, CSS, JavaScript code semantic, you can use Jsoup and iterate each element in order to highlight them with styles. One example usage of Jsoup in Android is shown here.
Above two will show you highlighted output, but not editable as you type. One definite thing to do is to use EditText.addTextChangedListener event handler. Rest of editing and displaying fine Spannable result can be found from EditText with Emoticons trials.
To display the emoji button in the soft keyboard I use this in the EditText:
android:inputType="textShortMessage"
which uses the emoji icons for my device (which may be specific to my carrier/phone model).
I want to use my own set of drawables instead. Is there a way to do this without having to create a completely new soft keyboard?
No, there isn't any single line solution, maybe there is one at Lollipop as it is shipped with emoticons.
Options:
Implement a keyboard (needs a lot of effort + user to change his default keyboard)
Implement a panel/dialog that act as keyboard (needs less effort)
Use an existing library to do so a list of libraries is here but you can search for more if you want!
I was able to solve this by using the EmojiHandler from here:
To get the unicode of the emoji from textual message content:
String s = EmojiHandler.decodeJava(content);
// use decoded string to display emoji in TextView, Button, etc
textButton.setText(s);
To encode the emoji from the softkeyboard and put it into a String:
String encodedEmoji = EmojiHandler.encodeJava(msgText);
My application uses Android 4.0 on Samsung Galaxy S3.
I want to integrate Emoji character support in EditText field in Android application.
Can anyone suggest me, how can I achieve it?
For example, In whatsapp and wechat application, TextField does support Emoji keyboard characters, but in my application it shows ? for each character I type using Emoji keyboard.
text_message = (EditText) findViewById(R.id.editText1);
text_view = (textView) findViewById(R.id.textView1);
btntest = (Button) findViewById(R.id.button1);
btntest.setOnClickListener(new OnClickListener()
{
public void onClick(View v)
{
text_swype.setText(text_message.getText().toString());
}
});
and i also try https://github.com/IPL/iOSStyleEditText
and font of emoji from http://klncity1.wordpress.com/tag/emoji/
but not work
It depends on the font that is used for the TextView or its subclasses like EditText.
Every View can display emoji because there are hundreds of emoji included in Unicode and those have also become the default that most emoji keyboards and apps like WhatsApp use.
However, you won't see those colorful images as you see in WhatsApp, for example. This is because WhatsApp uses custom fonts/images for these emoji which replace the default appearance.
But if you add emoji to a text field in your normal "Messages" application or somewhere else, you should see the normal Android style which is monochrome emoji showing the Android robot.
Here's a list of common emoji and their Unicode codepoints:
https://github.com/delight-im/Emoji
They're all supported in Android's normal font. I guess you may have changed the font of your EditText in the layout.
You can use EmojiconTextView or EmojiconEditText from this library : https://github.com/rockerhieu/emojicon
Here is the list of available emoji Unicode
Sending content to Server you need to use org.apache.commons.lang3.escapeJava(...) and when getting data from server you need to reverse Unicode to emoticon so you have to use org.apache.commons.lang3.unescapeJava(...)
You have to use "EmojiconEditText" From the Library.
It will display Eemojies.
Use any one of these.
EmojiconTextView: a TextView which can render emojis.
EmojiconEditText: a EditText which can render emojis.
EmojiconGridFragment: a fragment contains emojis in a GridView for the user to choose.
EmojiconsFragment: a fragment contains many set of emojis for the user to choose.
Below is Util from org.apache.commons.lang3
Answer posted by #AZ_ is right but the util name has updated as below :
Send string to server as :
org.apache.commons.lang3.StringEscapeUtils.escapeJava(mEdText1.getText().toString()
Read String from server as :
org.apache.commons.lang3.StringEscapeUtils.unescapeJava(mData.get(position).getText())
Is there a way to represent special HTML characters in a EditText in Android? I want to display symbols like section signs (§), bullet points (), degrees (°), etc.
Is there a way to do this?
Thanks!
EDIT: The original post had asked about a TextView, but my intended question is about EditTexts. I want the user to be able to press the button corresponding to the symbol they want, and the symbol will be added to the EditText, and they then resume typing.
Have you tried \u00A7 \u2022 and \u00B0 in setText?
That are unicode numbers of those characters.
For EditText, you just have to create buttons with mEditText.getText().append(character) and probably mEditText.focus().
Have you looked at the Html.fromHtml(...) methods?
Alternatively you could just use a WebView instead of a TextView and use loadData(...) to load an HTML string.