How to show Hindi(non-english) webpages using web view in android application -
i developing android application need load url contains hindi fonts in web view.
i used following code this:
webview webview = (webview) findviewbyid(r.id.webview); websettings settings = webview.getsettings(); settings.setjavascriptenabled(true); settings.setbuiltinzoomcontrols(true); settings.setsupportzoom(true); settings.setdefaulttextencodingname("utf-8"); webview.setscrollbarstyle(webview.scrollbars_outside_overlay); webview.getsettings().setloadwithoverviewmode(true); webview.getsettings().setusewideviewport(true); webview.loadurl(url);
this code working fine in of latest devices , showing hindi contents properly. but in android 2.2, 2.3 or other lower versions, showing boxes rather hindi charactors.
how can support web view enabled non-english test application can run on devices.
thanks in advance...
try below link :click here
private boolean copyfile(context context,string filename) { boolean status = false; try { fileoutputstream out = context.openfileoutput(filename, context.mode_private); inputstream in = context.getassets().open(filename); // transfer bytes input file output file byte[] buf = new byte[1024]; int len; while ((len = in.read(buf)) > 0) { out.write(buf, 0, len); } // close streams out.close(); in.close(); status = true; } catch (exception e) { system.out.println("exception in copyfile:: "+e.getmessage()); status = false; } system.out.println("copyfile status:: "+status); return status; }
3.you have call above function once (you have find logic this).
copyfile(getcontext(), "myfont.ttf");
4.use below code set value webview. here using css set font.
private string gethtmldata(context context, string data){ string head = "<head><style>@font-face {font-family: 'verdana';src: url('file://"+ context.getfilesdir().getabsolutepath()+ "/verdana.ttf');}body {font-family: 'verdana';}</style></head>"; string htmldata= "<html>"+head+"<body>"+data+"</body></html>" ; return htmldata; }
5.you can call above function below
webview.loaddatawithbaseurl(null, gethtmldata(activity,htmldata) , "text/html", "utf-8", "about:blank");
Comments
Post a Comment