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.
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.
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.
Display HTML code using TextViewsetText(Html. fromHtml(descriptionUsingTextView)); In the snippet code above, we using the method Html. fromHtml(String source, int flags).
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);
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With