Android WebView font size in pixels

I would like to set the font size that I use in WebView for a specific pixel size. I'm doing something line by line

<p style="font-size: 18px">Text</p> 

However, the font size is different on different devices. Any idea how to make this work?

Thanks!

+6
source share
3 answers

I found a solution adding the following meta tag in HTML

  <meta name=\"viewport\" content=\"target-densitydpi=device-dpi\" /> 
+6
source

You can use web browsing to get the settings object and setDefaultFontSize(int size) to set the default font size.

eg:

 myWebView.getSettings().setDefaultFontSize(20); 

Alternatively, you can use the setInitialScale(int percentage) method in your web view to set the required percentage scale, you can try it with different percentages and see which one you are like.

eg:

 myWebView.setInitialScale(85); 

You can also use the setBuiltInZoomControls(boolean value) to get its settings object, and then use the setBuiltInZoomControls(boolean value) method to enable / disable the user to use the default zoom value so that they can scale according to their preferences.

eg:

 myWebView.getSettings().setBuiltInZoomControls(true); 
+2
source

None of me worked, I needed to do this:

 WebSettings settings = wv.getSettings(); if (Utils.hasIceCreamSandwich()) settings.setTextZoom( (int)(settings.getTextZoom() * 1.2)); else { settings.setTextSize(WebSettings.TextSize.LARGER); } 
0
source

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


All Articles