How to set custom font to a html loaded with a WebView in Android?
Try this solution:
String text = "<html><head><style type=\"text/css\">@font-face {font-family: MyFont;src: url(\"file:///android_asset/font/Montserrat-Regular.ttf\")}body {font-family: MyFont;font-size: medium;text-align: justify;}</style></head><body>";
String pas = "</body></html>";
String myHtmlString = text+ YourTxext + pas;
wv.loadDataWithBaseURL(null,myHtmlString, "text/html", "UTF-8", null);
Custom font for webview
There is a bug report for Android that seems to suggest that custom fonts don't work for certain languages (Thai, Hebrew, Farsi, and Arabic have been mentioned). This hasn't been confirmed by anyone from Google, but there are a number of people reporting the same problem.
One of the suggested solutions (which at least one user confirmed as working) was to convert the font from otf to svg. There are a number of online tools that will do this for you (Everything Fonts is one example), but you may have issues with this being a copyrighted font - make sure your font license permits such conversions.
Also, when you have converted the font, open it up in a text editor and check whether the svg element is namespaced. It should look something like this:
<svg xmlns="http://www.w3.org/2000/svg">
If it is just <svg>
without the namespace, you may need to add the xmlns attribute manually. Apparently, svg fonts without the namespace don't work either.
Related Topics
Scale Image to Fill Imageview Width and Keep Aspect Ratio
Android Lollipop, Appcompat Actionbar Custom View Doesn't Take Up Whole Screen Width
Android Studio - Importing External Library/Jar
Asynctask and Looper.Prepare() Error
Java.Lang.Noclassdeffounderror: Javax.Activation.Datahandler in Android
Android Eclipse Ddms - Can't Access Data/Data/ on Phone to Pull Files
How to Add a Line Break in an Android Textview
Creating a Custom Layout for Preferences
How to Use Single Textwatcher for Multiple Edittexts
How Does the Mapping Between Android Resources and Resources Id Work
Why Are Most UI Frameworks Single Threaded
Comparing Two Drawables in Android
How to Avoid "Illegalstateexception: Scrollview Can Host Only One Direct Child"
Android Studio:How to Uninstall APK (Or Execute Adb Command) Automatically Before Run or Debug