0

I find Android's web view behaviour strange when handling with css properties:

When displaying a web page that contains the following css properties: font-size and line-heightset to:

font-size: 20px;
line-height: 35px;

Android's webview changes the properties to:

font-size: 17.4px;
line-height: 30.45px;

Why?

M. Feyz
  • 359
  • 2
  • 9
  • It might be of an extra settings for font-size or zoom. Even in browser, general settings, accessibility settings, display settings, android general font-size settings etc. – Ali Sheikhpour Feb 28 '18 at 09:13
  • Possible duplicate of [How to set text size in WebView in android](https://stackoverflow.com/questions/21694306/how-to-set-text-size-in-webview-in-android) – mpro Feb 28 '18 at 09:22

2 Answers2

2

I found answer:

Just webView must be to set text size to "NORMAL" in android. Like this:

webView.getSettings().setTextSize(WebSettings.TextSize.NORMAL);
M. Feyz
  • 359
  • 2
  • 9
  • Thanks, I was trying to find why this was happening. Btw Deprecated, Use webView.getSettings().setTextZoom(100); This will override the system font size on android webview to keep as normal. – panther Jan 29 '19 at 15:20
0

Did you check page behavior in different resolutions? There might be defined @media rules in CSS, which change the style for different resolutions, for example:

@media screen and (min-width: 1024px) {
    p {
        font-size:20px;
        line-height:35px
    }
}

@media screen and (max-width: 1023px) {
    p {
        font-size:17.4px;
        line-height:30.45px
    }
}

Read more here.

mpro
  • 14,302
  • 5
  • 28
  • 43
  • Set this properties in element self style without defined media. In tablet and also in mobile chrome browser work true. but in application in mobile work wrong! – M. Feyz Feb 28 '18 at 09:16
  • Try also [here](https://stackoverflow.com/questions/3796176/how-to-change-the-fontsize-in-an-android-webview) – mpro Feb 28 '18 at 09:23