0

I am using WebView and applying some styling to WebView's text. My fonts are located in the res/font folder right now and I am using those fonts to apply custom font. I creating my own html and applying font like this:

<html>
    <head>
        <style type="text/css">@font-face {font-family:MyFont; 
        src: url("file:///android_asset/fonts/open_sans_regular.ttf")}
        body {font-family: MyFont;}
        </style>
    </head>
    <body>

    //MY CONTENT GOES HERE

    </body>
</html>

Everything is working fine. But my problem is this solution making me copy font inside res/font to assets folder. Because I have to reference font like this file:///android_asset/fonts/open_sans_regular.ttf. Not only this copying is bad practise but also increasing the size of my apk.

My quesion is/are:

  1. How can I access file path (of the font that is located in the res/fonts) and use it instead of this file:///android_asset/fonts/open_sans_regular.ttf so that I do not have to copy my fonts?

  2. You might probably suggest why not move those font completely to assets folder. I cannot do this because those fonts are refernced in my styles. Like this:

 <style name="Font.OpenSans.Light">
        <item name="android:fontFamily">@font/open_sans_regular</item>
 </style>

As you can see, removing those fonts will cause issues in my styles. May be, I can move the fonts to assets folder and access them from styles? Is this even possible?

Any suggestios would be greatly appreciated.

Azizjon Kholmatov
  • 1,136
  • 1
  • 13
  • 26

0 Answers0