3

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

miladrasooli
  • 115
  • 1
  • 10

1 Answers1

1

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.

  • 2
    I have tested my app on android 4.4.2 and it works fine and I have tested on Galaxy Note 10.1 2014 and it was not... – miladrasooli Mar 21 '14 at 14:31
  • 1
    That is really a problem with different versions of Android. Also it doesn't work on 3.0 :| –  Mar 21 '14 at 14:32