0

I am displaying my content on Webview as loadData method

  webview.loadData(WS.welcome_header_text,"text/html","UTF-8");

Here my WS.welcome_header_text =  <div style="text-align: center;"><span style="color: rgb(255, 255, 255); font-size: x-large; background-color: transparent;">Please share your feedback with us</span></div>

There is no font-family specified from my backend API but I want to know what font family is taken by my android web view as default.

enter image description here

When It shows Content "Please share your feedback with us" on the above screenshot.

B.shruti
  • 1,589
  • 1
  • 21
  • 41

2 Answers2

1

WebView has provided us with the methods to check the default fonts like -

  1. webview.getSettings().getStandardFontFamily()
  2. webview.getSettings().getFixedFontFamily()

and As WebView Safe fonts Suggested, My default fonts which are applying, I get it through StandardFontFamily(sans-serif) font-family in my case and Arial/Verdana fonts in particular.

B.shruti
  • 1,589
  • 1
  • 21
  • 41
0

Give your span tag an ID say my-text and run the following code

String js = "(function(){var element = document.getElementById( 'my-text' );return window.getComputedStyle( element, null ).getPropertyValue('font-family');})()";

webView.evaluateJavascript(js, new ValueCallback<String>() {
    @Override
    public void onReceiveValue(String s) {
        Log.d("FontFamily", s); 
    }
});
Sahil Manchanda
  • 9,812
  • 4
  • 39
  • 89