android webview 顯示其字體的默認字體系列是什麼? (What is the default font family taken by android webview to show its fonts?)


問題描述

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 web 視圖默認採用。

enter image description here

當它顯示內容時“請與我們”在上面的屏幕截圖中。


參考解法

方法 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.

方法 2:

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

(by B.shrutiB.shrutiSahil Manchanda)

參考文件

  1. What is the default font family taken by android webview to show its fonts? (CC BY‑SA 2.5/3.0/4.0)

#android-webview #font-family #Android #default-value






相關問題

如何在我創建的 Android WebView 中播放動態 mp4 視頻 (How do I play dynamic mp4 video within Android WebView I created)

Phonegap 應用程序不滾動 (Phonegap Application Not Scrolling)

Android - 將本地圖像設置為 WebView 中的 img 元素 (Android - Set a Local Image to an img element in WebView)

使用 webView 的 loadDataWithBaseURL 不從 sdcard 加載圖像 (Using webView's loadDataWithBaseURL not loading images from sdcard)

WebView LoadURL dan GetView (WebView LoadURL and GetView)

Android WebView 在 android 4.0 + 上崩潰應用程序 (Android WebView crashes application on android 4.0 +)

Android: Chế độ xem hình ảnh chụm-thu phóng với Chế độ xem con được nối thêm (Android: Pinch-zooming ImageView with appended child Views)

android.webkit.WebView 無法轉換為 android.widget.Button (android.webkit.WebView cannot be cast to android.widget.Button)

使用 android studio 在 webview 中顯示谷歌表單 (display google forms in webview using android studio)

如何解決使用 WebView 時出現“無法打開數據庫文件”的錯誤? (How to solve error "unable to open database file" when using WebView?)

android webview 顯示其字體的默認字體系列是什麼? (What is the default font family taken by android webview to show its fonts?)

Android Studio - 視頻音量低 (Android Studio - Video Volume Low)







留言討論