I am porting an app that displays Hebrew to Android 2.3. The 2.3 emulator displays the strings correctly when in a TextView, but when I try to put the strings in a WebView, the webview just displays gibberish.
This tells me that the Hebrew fonts are available in the emulator but the webview code has something missing.
This is the code:
WebView mWebView = (WebView) findViewById(R.id.webview);
mWebView.loadData("<html><body>"+temp1 +"</body></html>",
"text/html", "UTF-8");
Any ideas on how to get the emulator to display the webview correctly.
When you display the page, you aren't giving a way for the browser to know that your page uses a right-to-left script.
You can use the HTML dir attribute in a markup element that surrounds your right-to-left text (it should detect automatically which characters to reverse, and which not to). (For more details, look at this note from W3C - it seems to be implemented in Chrome at least.)
Probably the most expedient way would be to rewrite the first tag as:
<html dir="rtl">
I changed the font of the webview by adding
mWebView.getSettings().setFixedFontFamily("DroidSansHebrew.ttf");
The text is rendered in the correct font but left-to-right which is not the correct orientation for Hebrew.
Related
I have a html string that I want to display in TextView. The html string has css inline style and also css in header. I would like to ask if I can display the html string with css in TextView?
I tried Html.fromHtml(), but the css doesn't apply.
Android native TextView doesn't support all HTML tags and features. It only does support a few tags and properties. So, in your case, there's a couple of options which you may want to consider.
Use WebView to show rich texts. However, WebViews are too heavy and slow.
Use 3rd party libraries that improve native TextView and support more HTML tags. For example: HTML-TextView.
Android does not support CSS in TextView and has a limited Html markup support. Use WebView instead.
So I have an HTML string I want to display as styled text in a textview but it never seems to work. My HTML string uses tags which are supposed to be supported by the fromHtml() method but it never displays the text properly, just returns the original HTML string. Here's an example of my HTML:
<div class="className"><p>Sample text http://www.example.com</p></div>
Nothing special as you can see, yet it never parses it correctly. Could it be that the method doesn't support the "class" attribute? If so, how do I add support for it?
Html class provides limited to support of HTML elements. And "class" attributes are not supported.
To understand which tags can be used and how they will be rendered refer to source code (android 5.0.1 r1). You can provide custom TagHandler or use WebView to display complex HTML page.
Give a try to this lib: https://github.com/SufficientlySecure/html-textview
It supports several tags more than native Html.fromHtml in Android.
I have a problem. I have to change the font in my webview. I mean I have a html page in assets and font of the html page is default font. I want to change font of the html page but it must be done in code in android application. This is possible?
this is my hebrew content :
<string name="test">בְּרֵאשִׁ֖ית בָּרָ֣א אֱלֹהִ֑ים אֵ֥ת הַשָּׁמַ֖יִם וְאֵ֥ת הָאָֽרֶץ׃</string>
When i display in textview it is display correct format. But when i display in webview it display wrong.
I used this but not any effects DIR='RTL' LANG='HE' ALIGN='JUSTIFY' in html. I want to display in webview.
It is a known bug in WebView with strings that include nekudot (vowels). Note that it appears to have been fixed in Ice Cream Sandwich (Android 4.x) and above.
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?