How can I show turkish chars (ş, ğ, ü ...) in webview as loadData?
My webview is: mWebView.loadData(detailsHtml, "text/html", "UTF-8");
thanks.
webView.loadData(htmlStr, "text/html; charset=utf-8", null);
This line of code saved me to deal with turkish character set. I hope it helps others too.
Try this code
mWebView.loadDataWithBaseURL(null,"ş, ğ, ü ","text/html", "UTF-8", null);
Related
I have a text (sInfoText) with a lots of special characters like 'è'.
I would like to show this special character also in a webview, but I get rubbish characters. Howto convert this special characters programmatically?
wvinfo.loadData(sInfoText,"text/html", "UTF-8");
try
wvinfo.loadData(sInfoText, "text/html; charset=UTF-8", null);
this ll work on above 4.0.0
I have a same problem like
this
Problem gets solved with loadData()
But it doesnt works with loadDataWithBaseURL()
v.loadDataWithBaseURL("file:///android_asset/index/",htmlDocument, "text/HTML", "UTF-8",null);
Please help..
OK i got it...
its simple we just need to change HTML to html i.e.(Capital to small letters)
Try something like this:
webView.loadDataWithBaseURL(null, "<body><font size='+2'>My text</font></body>", "text/html", "utf-8", null);
You can simply use
mWebView.loadUrl("file:///android_asset/privacy.html");
I had Database in which data stored in hindi as \u092e\u0948\u0902 \u0924\ and setting that content to webview using below.
webview1.loadData(hindi_content, "text/html", "UTF-8");
But it will display as
I don't know why that's happening. Any one please suggest. how to fix that !
This happens because of a bug with the encoding parameter of loadData in most Android versions. This parameter is ignored for some reason so the UTF-8 based hindi characters will not be rendered.
To fix this you can use one of the following alternatives.
webview1.loadData(hindi_content, "text/html; charset=UTF-8", null);
webview1.loadDataWithBaseURL(null, hindi_content, "text/html", "utf-8", null);
This is a duplicate of this answer:
You will also need to unescape those sequences and to do that refer to How to Unescape Unicode in Java
Rendering UTF-8 in a WebView using loadData has been broken in some form or fashion forever.
Issue 1733
Use loadDataWithBaseURL instead of loadData.
// Pretend this is an html document with those three characters
String scandinavianCharacters = "øæå";
// Won't render correctly
webView.loadData(scandinavianCharacters, "text/html", "UTF-8");
// Will render correctly
webView.loadDataWithBaseURL(null, scandinavianCharacters, "text/html", "UTF-8", null);
Now the part that is truly annoying is that on the Samsung Galaxy S II (4.0.3) loadData() works just fine, but testing on the Galaxy Nexus (4.0.2) the multi-byte characters are garbled unless you use loadDataWithBaseURL(). WebView Documentation
you will need to use font in order to support hindi (Hindi language is not yet fully supported by android)
create Singleton instance of Typeface and invoke createFromAsset();
and add it to WebSettings like this
WebSettings webSettings = webView.getSettings();
webSettings.setFixedFontFamily(InstaceOFTypeFace);
Finally I have come up with the solution of Loading hindi content to the webview.
I had simply change my loading string and unfortunately it will work.
webview.loadData(Hindi_css, "text/html; charset=UTF-8", null);
Thank you all for your effort. :)
You can use this one also.
String uri= Uri.encode(html file/url);
webView.loadUrl(uri);
may be this will help you.
Can any one please tell which other characters need to be converted before loading the data in webview.
view.loadDataWithBaseURL("data:",htmlString, "text/html",
"utf-8", htmlString);
Try ("data://", htmlString, "text/html", "utf-8", null).
That should load, although the back button behavior might not be correct.
I have a WebView using following code:
WebView webView = new WebView(cont);
webView.loadData("Red 20%", "text/html", "utf-8");
It is having trouble showing the string. But if I remove the '%' character from the string it is showing properly. What is wrong with the code? How do I display '%' in WebView?
Simple:
WebView webView = new WebView(cont);
webView.loadData("Red 20%", "text/html", "utf-8");
You can see the special characters here:
http://www.degraeve.com/reference/specialcharacters.php
URL encode the %
20%25 should do the trick
An easier alternative is to use TextUtils.htmlEncode() for the strings you want to display.
WebView webView = new WebView(cont);
String s = TextUtils.htmlEncode("Red 20%");
webView.loadData(s, "text/html", "utf-8");
Instead of % you have to useits equevalent to show it in web. actually it is % so that your code should change to
webView.loadData("Red 20%", "text/html", "utf-8");
You can replace "Red 20%" -> "Red 20 %"