I am trying to establish a new custom font (otf file) for my web view.
I put anbaaarabic_bold.otf in assets file.
There is how i do:
String head = "<head><style>@font-face {font-family: 'verdana';src: url('file://"+ getActivity().getFilesDir().getAbsolutePath()+ "/anbaaarabic_bold.otf');}body {font-family: 'verdana';}</style></head>";
String htmlData= "<html>"+head+"<body style=\"font-family: verdana\">"+body+"</body></html>" ;
mBodyArticle.loadDataWithBaseURL("http://nada", htmlData,
"text/html", "utf-8", "");
body : contain my html code.
I don't know why the font is not working for my webview. body html font doesn't change.
There's an app called iFont that helps you to find plenty of fonts to use. This app allows you to easily browse a sizable selection of fonts that you can download and install. Note: All other Android devices must be rooted for iFont to work.
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With