android webview 用来显示其字体的默认字体系列是什么?

What is the default font family taken by android webview to show its fonts?

我在 Webview 上显示我的内容作为 loadData 方法

  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>

我的后端 API 没有指定字体系列,但是 我想知道我的 android 网络视图默认使用什么字体系列。

当上面的屏幕截图显示内容 "Please share your feedback with us" 时。

给你的 span 标签一个 ID 说 my-text 和 运行 下面的代码

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); 
    }
});

WebView 已经为我们提供了检查默认字体的方法,比如-

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

并且按照 WebView Safe fonts 的建议,我正在应用的默认字体是通过 StandardFontFamily(sans-serif) 获得的 在我的例子中是字体系列,特别是 Arial/Verdana 字体。