Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

TextView with html table

Tags:

android

I have a problem. I want to put in to the "TextView" html format text. I add the like below.

<string name="text"><![CDATA[<table><tr><th bgcolor= #FF0000>some text</th></tr> <tr><td bgcolor= #FF0000> some text</td></tr>]]></string>

and put it into the TextView as:

mInfoText.setText(Html.fromHtml(getString(R.string.text)));

but after run application, displayed text in TextView is not formatted.

like image 431
monawi Avatar asked Dec 10 '12 11:12

monawi


People also ask

Can I use HTML in Android?

In Android, we usually need HTML files for displaying the content in WebView. If the developer wants to add any website page or want to create a local webpage for the app then it could be done using HTML files.

How to parse HTML content in Android?

This example demonstrates how do I parse HTML in android. Step 1 − Create a new project in Android Studio, go to File ⇒ New Project and fill all required details to create a new project. Step 2 − Add the following code to res/layout/activity_main. xml.

How do I view HTML code in Android?

Display HTML code using TextViewsetText(Html. fromHtml(descriptionUsingTextView)); In the snippet code above, we using the method Html. fromHtml(String source, int flags).


1 Answers

try whit WebView

String html = "<table><tr><th>text1</th></tr><tr><td>text2</td></tr></table>";
webView.loadDataWithBaseURL(null, html, "text/html", "utf-8", null);
like image 91
Vasil Valchev Avatar answered Oct 06 '22 00:10

Vasil Valchev