How to change the FontSize in an Android WebView?

Viewed 53611

How can you manually change the font size of a webview? e.g. When the page loads up in the webview the font size is like 24pt. and way too large for my android's screen. I've looked into the "websettings" but it seems that the two are not related.

Thanks

5 Answers

If you want to increase or decrease font Size of WebView dynamycally than use these lines of code:

WebView mWebView;
int fontSize;
    @Override
    public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_main);
    mWebView = findViewById(R.id.webview);
    mWebView.loadUrl("file:///android_asset/sample.html");
    // enable / disable javascript
    mWebView.getSettings().setJavaScriptEnabled(true);
    mWebView.getSettings().setSupportZoom(true);
    mWebView.getSettings().setBuiltInZoomControls(true);
    mWebView.getSettings().setDisplayZoomControls(true);
    fontSize = mWebView.getSettings().getDefaultFontSize();
}
 private void fontSizePlus() {
    fontSize++;
    this.changeFontSize(fontSize);
}

private void fontSizeMinus() {
    fontSize--;
    this.changeFontSize(fontSize);
}

private void changeFontSize(int value) {
    mWebView.getSettings().setDefaultFontSize(value);
}

public void Inc(View view) {
    fontSizePlus();
}

public void Dec(View view) {
    fontSizeMinus();
}
Related