HTML in your Droid App?
If you’re like me when it comes to applications, you think in terms of HTML, not necessarily in terms Views as found in android manifest files. I should be able to apply multiple look and feels throughout a single block of text, not be forced to make a new one every time I want to change it. Lucky for us, the android SDK has a class already for those of us who think in terms of HTML, the aptly named HTML class.
I ran into this when writing a fairly common group of text, the field name followed by a text description. I wanted the field name to be set in bold with the rest of the text and description to be normal. With views, you can break them into two separate views: one for the field name; and a second for the description, setting the first to be bold. This will work just fine, but now you have two elements that you have to position instead of one. Wouldn’t it be easier if we could just do a single view with some text set to bold? HTML.fromHtml(“string containing your html”) will do that for us.
An example of this is found in a stackflow.com entry that shows how html tags can be placed to give the desired effects. Now we have a single element, styled how we want, to position without having to worry about losing our consistent spacing between the field name and description.
I would not recommend trying to do your entire application this way, but for simple text views, it works beautifully.

Comments
Be the first to comment!
Leave A Comment