LevanIlashvili
LevanIlashvili

Reputation: 26

Android - unicode characters aren't displayed correctly

I'm trying to load local html file:

    WebView webView = (WebView)findViewById(R.id.webView1);
    webView.getSettings().setDefaultTextEncodingName("utf-8");
    webView.setWebChromeClient(new WebChromeClient());
    webView.loadUrl("file:///android_asset/www/index.html");

index.html contains this:

<html>
    <head>
        <meta http-equiv="Content-Type" content="text/html; charset=UTF-8"/>
    </head >
    <body>
        რაღაც ტექსტი
    </body>
</html>

but it doesn't work. Can anyone help? P.S. that text is in Georgian

Edit: I've tried loading that text using almost every possible method I've found - loadDataWithBaseURL and loadData methods didn't work either.

Closed: Here is the problem: That version of Android didn't recognize Georgian characters.

Upvotes: 1

Views: 2630

Answers (3)

G&#246;ksel G&#252;ren
G&#246;ksel G&#252;ren

Reputation: 1479

You can use this approach;

String start = "<html><head><meta http-equiv='Content-Type' content='text/html' charset='UTF-8' /></head><body>";
String end = "</body></html>";

webView.loadData(start + YOURCONTENT + end,"text/html; charset=UTF-8", null);

Upvotes: 1

Faisal
Faisal

Reputation: 51

You can use HTML codes of UNICODE characters to display them in WebView.

Just replace the characters with their respective html code.

Refer here for Html codes of Georgian characters.

Upvotes: 5

Lazy Ninja
Lazy Ninja

Reputation: 22527

Ensure that your file is actually encoded as UTF-8.
Check if your editor save it as UTF-8. It could be the problem.

Upvotes: 0

Related Questions