Alex Rivera | Logout

Custom font for webview

Asked 2013-08-03T12:23:49.943
8

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.

Edit
Report

1 Answer

2

Is your phone running Android 2.1 by any chance?

There is a known bug in 2.1. As a result, custom fonts won't work for 2.1. But this should work for 1.5, 1.6 and 2.2.

You can find more information here.

answered 2013-08-03T14:09:57.247

Your Answer