【问题标题】:What is the default font family taken by android webview to show its fonts?android webview 显示其字体的默认字体系列是什么?
【发布时间】:2019-12-30 07:36:43
【问题描述】:

我在 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 web 视图默认采用的字体系列。

当它在上面的屏幕截图中显示“请与我们分享您的反馈”内容时。

【问题讨论】:

    标签: android android-webview default-value font-family


    【解决方案1】:

    给你的 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); 
        }
    });
    

    【讨论】:

    • 好的,我试试看。
    • 好吧,我没有为我工作,因为我已经告诉过“我的后端 API 没有指定字体系列”,所以我的 标签没有任何字体-家庭钥匙
    【解决方案2】:

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

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

    正如WebView Safe fonts 建议的那样,我正在应用的默认字体,我通过 StandardFontFamily(sans-serif) 就我而言,字体系列,尤其是 Arial/Verdana 字体。

    【讨论】:

      猜你喜欢
      • 2017-01-24
      • 1970-01-01
      • 1970-01-01
      • 2019-03-22
      • 2014-03-06
      • 1970-01-01
      • 2011-05-16
      • 2016-04-09
      • 1970-01-01
      相关资源
      最近更新 更多