" + "

" + getS" /> " + "

" + getS" /> " + "

" + getS"/>

webview justify not show Persia(Farsi)/RTL Language Correctly

1.2k views Asked by At

i need to make justify for webview to show Persian(Farsi)/RTL String.

i use below code :

    String text = "<html><body>"
                      + "<p align=\"justify\">"                
                      + getString(R.string.test1) 
                      + "</p> "
                      + "</body></html>";
            webView.loadData(text, "text/html", "utf-8");

but webview can't show persian character - below image :

enter image description here

what i to do?

2

There are 2 answers

0
Saeid On BEST ANSWER

Ok , Finally i found a good way to make justify + using "\n" + all other customize for String.

  1. i make a HTML file contain customized string
  2. Load data to WebView to thisway :

    webView.loadUrl("file:///android_asset/string.htm");
    

Edit :

webView.loadDataWithBaseURL(null, yourString, "text/html", "utf-8", null);

0
K. Maksym On

To load data use

webView.loadData(text, "text/html; charset=UTF-8", "utf-8"); 

By default this does not support RTL. To fix it I use HTML tag:

String headerText = "<html><body dir=\"rtl\"; style=\"text-align:justify;background-color:#fff3eb;\">";

And to end of String add:

String footerText = "</body></html>";