Why Android WebView does not display properly HTML page with Hebrew text when text-align set to "justify"

2.6k views Asked by At

I want to display local html file on a WebView. (Android 2.3.3)

The HTML contains Hebrew text. I want the text to be justified, so in my css file I do the following:

body
{ 
    text-align: justify; direction: rtl;
}

But for some reason the text end up being messed up: Text aligned to left...

And this is definitely not "justified" but more aligned to the left.

Any idea how can overcome this problem? It's working perfectly fine on any other browser than the WebView. (Including WebKit based ones)

1

There are 1 answers

0
mvalenci On

This code worked for me:

@Override
protected void onCreate(Bundle savedInstanceState) 
{   
     super.onCreate(savedInstanceState);
     setContentView(R.layout.main);   

     WebView myWebView = (WebView) findViewById(R.id.webview);        
     WebSettings settings = myWebView.getSettings(); 
     settings.setDefaultTextEncodingName("utf-8"); 

     String webtext = "שלום";
String summary = "<html lang=\"he\"><body><p dir=\"rtl\">" + webtext + "</p></body></html>";
    myWebView.loadData(summary, "text/html", null); 

}