I wan to display html contents without using webview in android.
Contents are result of html parser.
But by now, I don't know how to do it. Is there any clue or example?
I think I need some example code to study it.
thank you very much.
You have to use Html.fromHtml()
Example :
myTextView.setText(Html.fromHtml("<h2>Title</h2><br><p>Description here</p>"));
Best Example here.
Related
I have some data which was formatted using MathJax on WebApplication. Now, I want to display those Data in Android App and that is in TextView only.I have already downloaded MathJax from Leathrum's WordPress
I found some examples but all are using WebView. But I want it using TextView. How to get this ???
I am also using ImageGetter with that TextView and it is working fine. Now, just want to do something for MathJax.
Why only TextView ???
My data contains simple text, html text, images, and math functions... I was using webview but it is showing extra space at bottom and also have using with Webview because I am using Custom ListView with WebView
But I want it using TextView. How to get this ?
You don't. TextView is not designed for this. Your choices are:
Stick with WebView
Figure out how to render your mathematical expressions to images, then either use an ImageView, ImageSpan, etc.
Write your own widget that draws the mathematical expression to a Canvas
MathJax is a cross-browser JavaScript library that displays mathematical notation in web browsers, using MathML, LaTeX and ASCIIMathML markup.
Source: MathJax in Wiki
The very first line has an answer for you. It's a cross-browser javascript library. you can not use it for textviews. Doesn't it make sense ?
Update:
Solution 1: You could write a mapper which will have mapping of each Math symbols to its html code and use it to showcase on your TextView based on need.
Solution 2: There is a nice open source: MathView Which is using MathJax internally that you can use.
If I have html with tags not supported as part of Html.fromText I understand a WebView will do the trick as it supports standard HTML as a browser but its performance is really slow to my liking. So if I don't want to use WebView, the only other way is to parse the HTML myself and put different tags in muliple TextView inside a vertical LinearLayout?
You'll have to use Html.fromHtml() with an Html.TagHandler to handle unknown tags like <pre/> and <code/>.
See this answer for an example of how to implement Html.TagHandler.
Use replaceAll() to convert the <pre> and <code> tags to <tt>, which is supported by Html.fromHtml(). Then, use Html.fromHtml() to create the SpannedString that you pass to the TextView.
How can i display html values in textview in android.
Sample output response is in this link: http://pastebin.com/KYMTKAss .
Similarly i ve many classes and values. How can i fetch these html values into a string and display them in Textview. Please guide me.
Thanks.
Have you tried with Html.fromHtml already?
You can parse HTML using JSoup. The jar is about 132k, which is a bit big, but if you download the source and take out some of the methods you will not be using, then it is not as big. Have a look on HTML Parsers
I need to load a page into a webview and then apply some custom css to it. This page is not under my control, so I can't simply add a CSS include or inline CSS within the page itself.
Right now I'm just doing an HTTP get request, putting the contents into a String, prepending the string with my custom css (in style tags), and finally doing a loadDataWithBaseURL() on the string.
Is there a more elegant/efficient solution?
Thanks!
Well using what is available in the Webview, you have probably done the best that could be done.
However, if you really want to do it elegantly, get the source codes of WebView and all the classes it needs. Alter them to ultimately add the function WebView.setCSS() (for example)... It is doable but it needs some time.
you can just try WebView.reload() just like :
if(first_loading){
w.loadUrl(DisplayActiviyParam.sd_html);
first_loading = false;
}else{
w.reload();
}
,what you need do is tu change your css file contents. Good lucky!
We have site urls having arabic language we want to display as it is in android webview but it is not showing as correctly it is showing in reverse. Can you help me????
There is a simple solution of it. As correct order letters display in reverse order. Why not we write reverse letters?
This link will help https://stackoverflow.com/a/13562693/1547539
Just set the encoding :
YourWebView.loadData(YourContentHtml, "text/html; charset=UTF-8", null);
I fully understand your issue, you mean:
[أحمد] Would show as [دمحا]
I am afraid this is not possible, I have seen some post around all confirm that can't be done in the mean time.
Android has the ability to use custom TTFs in views (though it's kind of a kludge, example on how to use custom typefaces in the API Demos), but I'm not sure how to extend this to WebView, or whether it's even possible. custom font with Webview
Also see: font face of Webview in Android?