How to set WebView font to the current device font?

Yes, I saw how to use a custom font using CSS, but I do not want this. I have an application with WebView and the whole application has a device font, but WebView has a default font for WebViews and it seems ugly.

I can get TypeFace by default:

Typeface.defaultFromStyle(R.style.YourTheme);

But how can I install it in WebView? Or how best to get the current TypeFace device and install it in WebView? Thank.

+4
source share
2 answers

If your HTML is local (on your device), you just need to put the CSS file and the link, as usual.

<title>Titulo de la web</title>
    <link rel="stylesheet" href="estilo.css">

Remember that the html file and CSS are in the resource directory.

0
source

I used this code to change the font in WebView and it worked for me

data_webview = (WebView) findViewById(R.id.dataload_wv);
String custome_style = "<html><head><style type=\"text/css\">@font-face {font-family: 
MyFont;src: url(\"file:///android_asset/font/roboto.ttf\")}body {font-family: 
MyFont;font-size: medium;text-align: justify;}</style></head><body>";
String pass_data = "</body></html>";
String finalString = custome_style + YourTxext + pass_data;
data_webview.loadDataWithBaseURL(null,finalString, "text/html", "UTF-8", null);
0
source

Source: https://habr.com/ru/post/1598260/


All Articles