Android 2.3 Hebrew fonts in Webview
I am porting an app that displays Hebrew to Android 2.3. The 2开发者_JS百科.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.
精彩评论