1

I wanna load my custom typeface or font to the web view. so I create a html file that contains typeface and text for webview like this:

<html>
<head>
<style type="text/css">
@font-face {
    font-family: my_font;
    src: url('file:///android_asset/fonts/yekan.otf') 
}
body {
    direction:rtl;
    font-family: my_font;
    font-size: large;
    text-align: justify ;
}
</style>
</head>
<body>
    my text
</body>
</html>

and then put this html file in assets folder and call it's like this:

myWebview.loadUrl("file:///android_asset/salamt_news_about.html");
WebSettings settings = myWebview.getSettings();
settings.setDefaultTextEncodingName("HTF-8");

All content load success fully but font won't changes. I tried many ways. I used .ttf font instead of .otf but still unsuccessfull. I think problem is with loading font path but cant find out how. when I changed src to: src: url('fonts/BYekan.ttf') It's just loads successfully in browser but not in phone.

Mahdi
  • 6,139
  • 9
  • 57
  • 109

0 Answers0