Android Multi format TextView

Hey Androids !!!

This is going to be my very first post on Android development.
You may know that I've written many posts on Dot Net, Java & iPhone. From today onwards, I will add Android to that list :)

So, if you're in a situation that you need to have a single label(TextView) with multiple formats, then this will be the post for you. It becomes very simple when you know a bit of html.

Here is a list of tags supported by Android TextView before you get started.
Have a look at this before you start.

Suppose you have a TextView named multiFormatView

TextView multiFormatView;

The first step is to build your HTML string.

String htmlString = "<b>This is bold</b>"+"And this is not.";

Now there is only one line of code. Just set the text to the TextView using.


multiFormatView.setText(Html.fromHtml(htmlString));

That's it.

So, it will print 

This is bold.And this is not.

You can juggle around with each of the tags supported to see how you can get your job done.
Happy coding my friends

:)



Comments

Popular posts from this blog

Encrypt and Decrypt Images Using Java

Build your own Network sniffer

ASP Response.Write newline