Gniewomir Gniewomir - 3 months ago 22
Android Question

Android webview portuguese characters

Characters in my webview are destroyed when i use utf-8. It displays question mark on black diamond background. When I use other encoding they are garbled. I've tried the solution from this thread, my code looks like

input = assetManager.open("xxx.html");
Integer size = input.available();
byte[] buffer = new byte[size];
input.read(buffer);
text = new String(buffer);

WebSettings settings = webView.getSettings();
settings.setDefaultTextEncodingName("utf-8");
webView.loadDataWithBaseURL("file:///android_asset/",text,"text/html; charset=utf-8", "utf-8",null);


the HTML header

<html ><head><meta http-equiv="Content-Type" content="text/html;charset=utf-8">
<meta name="xxxxx">
<title>xxx</title>

<style type="text/css">
@font-face {
font-family: fonttt;
src: url("file:///android_asset/roboto.ttf")
}

body {
font-family: fonttt;
font-size: medium;
text-align: justify;
}
</style>
</head>


I don't get why utf-8 doesn't work and why when I use other encoding (windows-1252, ISO-8859-1) characters are garbled.

Answer

You can save them in xml using html-code but, this is mostly not needed if they are in the UTF-8 notation, actual characters will also do:

<string name="my_string">&#65;</string>

Or, you can call setText() with unicode on the TextView:

textView.setText("\u266b");

here this will help you more : two website that I personally use to write in Icelandic, every single character you rae looking for is listed there

Characters table website 1

Characters table website 2