I'm displaying some html text coming from an ePub file inside my Android application through a WebView. However I'd like to set the font used no matter the font used in the ePub file. This is my activity code:
public class ContentViewActivity extends Activity {
WebView webView;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.content);
webView = (WebView) findViewById(R.id.webview);
webView.getSettings().setJavaScriptEnabled(true);
String displayString = getIntent().getExtras().getString("display");
if(displayString != null)
webView.loadData(displayString, "text/html", "utf-8");
}
}
}
I've tried using websettings or a base url as suggested in this question using:
if(displayString != null) {
webView.loadUrl("file:///android_asset/html/my_page.html");
webView.loadDataWithBaseURL("file:///android_asset/html/my_page.html", displayString, "text/html", "utf-8", null);
}
with
<html>
<head>
<style type="text/css">
@font-face {
font-family: MyFont;
src: url("file:///android_asset/fonts/bookerly.ttf")
}
body {
font-family: MyFont;
font-size: medium;
text-align: justify;
}
</style>
</head>
<body>
Your text can go here
</body>
</html>
however when I run it, it seems to be ignoring the base URL and simply displaying the original html. Is there a way to fix it or another way to proceed?
Thanks in advance,
PS: Of course I cannot change previously the CSS of the ePub file.