0

I want to set font of web view to marathi. Can anybody tell me how to that? Here is my code:

setContentView(R.layout.web);
web=(WebView)findViewById(R.id.webView1);
web.getSettings().setJavaScriptEnabled(true);
web.loadUrl("file:///android_asset/welcome.html");
gunar
  • 14,660
  • 7
  • 56
  • 87
  • What if you search yourself first: [android webview with custom font](https://www.google.co.in/search?q=android+webview+with+custom+font)? – Paresh Mayani Oct 01 '13 at 09:08

2 Answers2

0
htmlData = "<link rel='stylesheet' type='text/css' href='style.css'/>" + htmlData;

// lets assume we have /assets/style.css file

web.loadDataWithBaseURL("file:///android_asset/", htmlData, "text/html", "UTF-8", null);

OR

simple way to do

Put your html and css in your /assets/ folder, then load the html file like so:

web=(WebView)findViewById(R.id.webView1);
web.getSettings().setJavaScriptEnabled(true);
web.loadUrl("file:///android_asset/yourHtml.html");

then in your html you can reference your css in the usual way

<link rel="stylesheet" type="text/css" href="style.css" />

And for custom fonts you can use @font-face in that css like this

@font-face {
    font-family: 'akshar';
    src: url('fonts/akshar.ttf');
}

body {font-family: 'akshar';}

OR TRY OUT THIS

head="<head><style>@font-face {font-family: 'akshar';src: url('file:///android_asset/fonts/akshar.TTF');}body {font-family: 'akshar';}</style></head>";
                HtmlString = "<html>"+head+"<body>"+content+"</body></html>";  
MyWebView.loadData(HtmlString, "contentType=text/html", "charset=UTF-8");
Vaibs_Cool
  • 6,126
  • 5
  • 28
  • 61
-2

You can try this out

Webview wv = new webview(context);
WebSettings settings = wv.getSettings();
settings.setJavaScriptEnabled(true);
settings.setUserAgentString(Locale.getDefault().getLanguage());
Sanal Varghese
  • 1,465
  • 4
  • 23
  • 46