Android 2.3 Hebrew fonts in Webview

左心房为你撑大大i 提交于 2019-12-10 15:42:46

问题


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.


回答1:


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">



回答2:


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.



来源:https://stackoverflow.com/questions/4392521/android-2-3-hebrew-fonts-in-webview

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!