I want to use a Custom Font in a WebView in android Studio
public void loadHTLMContentText(String text, WebView view) {
String body;
String head = "<head><style><style type=\"text/css\">@font-face {font-family: 'Standard';src: url('file:///android_asset/fonts/Standard.ttf')}body {font-family: Standard;text-align: justify;}</style></head>";
if (text != null) {
body = text;
} else return;
String htmlData = "<html>" + head + "<body>" + body + "</body></html>";
view.loadData(htmlData, "text/html; charset=utf-8", "utf-8");
view.setBackgroundColor(0x00000000);
}
I use this code to generate the HTLM file with the content. The custom font ist under the Path C:\Users\julia\AndroidStudioProjects\AktienApp\app\src\main\assets\fonts.
Then I load the content in the webview with this
WebView text_1_a = (WebView) one.findViewById(R.id.text_slide_type_a_1);
preparer.loadHTLMContentText(getString(R.string.Historie1), text_1_a);
But it doesn't change the font. Anybody got my failure?