Change Font WebView AndroidStudio
The ttf-file is in the same folder as the .java
That is pointless for two reasons:
Android doesn't typically use random files alongside the Java classes
WebView
doesn't know about any of that, anyway
Create an src/main/assets/
directory (assuming that you are working in a typical Android Studio project). Put your font files there. Use loadDataWithBaseURL()
, using file:///android_asset/
as the URL. Then, hope for the best.
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
Animate Change of View Background Color on Android
Viewpager.Setoffscreenpagelimit(0) Doesn't Work as Expected
Clicking Urls Opens Default Browser
Check Android Application Is in Foreground or Not
Location of SQLite Database on the Device
How to Sign an Android APK File
How to Change Color of Button in Android When Clicked
How to Handle a Lost Keystore Password in Android
Firestore: Permission_Denied: Missing or Insufficient Permissions
Difference Between Oncreate() and Onstart()
How to Add a Border to the Top and Bottom of an Android View
Runtimeexception: Your Content Must Have a Listview Whose Id Attribute Is 'Android.R.Id.List'
How to Make a Phone Call Using Intent in Android
How to Change the Background Color of Action Bar'S Option Menu in Android 4.2
Listen to Volume Buttons in Background Service