简体   繁体   中英

android webview set font size system default?

i have webview loaded with custom htlm string

my problem is when i set my phone text size as largest the webview text still as normal or small

i found solution to set webview text size but its fixed

is there any way to make webview text size as system default text size ?

this is my webview setting

holder.message.getSettings().setTextSize(WebSettings.TextSize.NORMAL);

I got this to work:

        WebView webview = result.findViewById(R.id.webview);

        WebSettings settings = webview.getSettings();
        float scale = 100f*getResources().getConfiguration().fontScale;
        settings.setTextZoom((int)scale);

        webview.loadUrl("file:///android_asset/file.html");

It gets the scale from the system configuration, then uses that to set the zoom factor. In my HTML I added < font size="4" > to make it just a little bigger.

Perhaps the issue is with the html string you load into your webView. At some point you call webView.load(myHtmlString, . . .)

That html could well contain a font declaration, including the setting of the font size. For more on the font size html declaration, see: http://www.w3schools.com/tags/att_font_size.asp

To change the font size in your html, you might be able to do something like:

myHtmlString = myHtmlString.replace("14", "16"); 

Of course, that would change all instances of 14 into 16, even those not associated with font size.

Or your html may contain headers, like . Changing an to an makes the font bigger.

Hope that helps.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM