Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

samsung devices ignore webview custom font

I am making an Android application and I have used WebView with Custom Font in some of my activities. Now that I am testing my App on some android devices I see that samsung devices totally ignore my custom font and use their own font (Default Samsung Font) in webview! I am using loadDataWithBaseURL method of WebView and using "file:///android_asset/" as base URL. Thank you for your help.

Update: here is the code

String style2="<style type=\"text/css\">@font-face {font-family: 'myface';src:url('file:///android_asset/fonts/WebYekan.ttf') } body {font-family: 'myface'!important;line-height:25pt;overflow:hidden;color:#555;margin:0px;text-indent:0px;text-align:justify}</style>";
wv.loadDataWithBaseURL("file:///android_asset/","<html  dir=\"rtl\"><head><meta content=\"minimum-scale=1.0, width=device-width, maximum-scale=1.0, user-scalable=no\" name=\"viewport\"><meta content=\"text/html; charset=utf-8\" http-equiv=\"Content-Type\"/>"+style2+"</head><body>"+text+"</body></html>","text/html","UTF-8",null);
wv.setVerticalScrollBarEnabled(false);
wv.setClickable(false);
wv.setLongClickable(false);
wv.setFocusable(false);
wv.setFocusableInTouchMode(false);
wv.getSettings().setLoadWithOverviewMode(true);
wv.getSettings().setUseWideViewPort(true);
wv.getSettings().setLayoutAlgorithm(LayoutAlgorithm.SINGLE_COLUMN);

p.s: this code works in other devices like HTC,Huawei,LG ,etc. Android ver: >4

like image 203
miladrasooli Avatar asked Dec 04 '25 01:12

miladrasooli


1 Answers

Actually various fonts that worked correctly in a WebView in Android 4.1 no longer work in Android 4.2. Thy update the version you are using.


Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!