1

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?

Saeid
  • 2,261
  • 4
  • 27
  • 59
  • 2
    possible duplicate of [Android WebView UTF-8 not showing](http://stackoverflow.com/questions/3312643/android-webview-utf-8-not-showing) – Dev-iL Jul 21 '14 at 22:30
  • @Dev-iL , so tanx it was helpful - just , how i can use "\n" in text for showing in webview - i use "\n" but show "\n" no new line! – Saeid Jul 22 '14 at 10:18
  • I believe that in html a line break is done by '
    '
    – Dev-iL Jul 22 '14 at 11:25
  • @Dev-iL , right , but i read data from "getString(R.string.test1)",in this solution i must write String and i can not read data from string.xml – Saeid Jul 22 '14 at 12:12

2 Answers2

3

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);

Saeid
  • 2,261
  • 4
  • 27
  • 59
2

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>";
AesSedai101
  • 1,502
  • 2
  • 23
  • 37
K. Maksym
  • 31
  • 3