How to show Unicode character in a TextView in Android? - android

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 = "&#8226"
print("this is bullet a ${Html.fromHtml(bullet)}")

Related

How to use display html tags along with inline css in android. The content is passed from the server to android via an API

I have gone through this link for reference
https://commonsware.com/blog/Android/2010/05/26/html-tags-supported-by-textview.html
The information is right there on your link. To use it as a spannable you have to call the fromHtml() method on your textview. After initializing the component. Please refer to this question:
How to display HTML in TextView?
All your answers are there, sorry for not formatting the answer correctly I'm on mobile at the moment

Include emoji in button string

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

Android TextView Display HTML With DL DT tags

Is there anyway to display DL DT and DD tags inside a TextView? I tried this
rawString is an array of "<dt>Some Name</dt><dd>Some text</dd>"
StringBuilder builder = new StringBuilder();
builder.append("<dl>");
for (String s : rawString) {
builder.append(s);
}
builder.append("</dl>");
But this doesn't seem to be interpreted even if I use Html.fromHtml() when i set the text
setText(Html.fromHtml(builder.toString()));
I guess if this will never work then is there a way to display information like this in a single textview where we have a 2 column or 3 column data and to line up the columns?
Name: The name
tim: value
yells: yes
If I use Webview then the data looks like this:
Name:
The name
tim:
value
yells:
yes
Seems like there is no way to display this without using a listview
Html.fromHtml() handles a limited set of HTML tags. This blog post of mine from 2010 lists the then-current set, and I am not aware that it has changed much. Quickly eyeballing the source code does not indicate any obvious changes.
So, you have a few choices, off the top of my ever-so-balding head:
Do something other than those tags.
Add a TagHandler to your fromHtml() call and figure out how to set up spans that will format things the way you want.
Use a WebView.
I guess another question would if this will never work then is there a way to display information like this in a single textview:
Getting them aligned like that will be difficult without a monospace font. You might be able to go through some text-measurement stuff to try to determine the right amount of whitespace to add to get things to align, or invent some spans to fill the space. It's one of those things that strikes me as being painful but eventually doable.

Is there a way to store and display HTML with CSS to achieve text formatting in Android?

I'm creating a note taking app for Android and i would like the user to be able to format their text, i.e. bold, different text sizes.
What I would like to know is how can I do this bearing in mind the text will have to be store-able in a database.
Can i use a web view with a string of HTML i pull from the database and a custom defined CSS to style it on the user end?
I also know there is some sort of formatting class in Android but im unsure of how it work, im not convinced it would be easy to store the formatting information.
I think you should use Spannable text. See android.text.*. I think you should store the text in HTML markup. Also take a look at
http://developer.android.com/guide/faq/commontasks.html#selectingtext

Android app: Html formatting "[]" when importing text from database

When I in my android application import text from my database it returns text with a square symbol. The text in the database is pasted from a webpage so I belive it is som html formatting, [ENTER] etc.
Is it possible to make the textview understand the formatting and use it as it is intended to look in a webbrowser. I am not interested in changing the view if it can be avoided, just to make the textstring use the formatting to make \nl etc.
Any one know how it can be done.
Before setting the text in the TextView you can use the Html.fromHtml method on the text, this will format the text appropriately.

Categories

Resources