2013-03-04 87 views
11

我有一個靜態html文件「myhtml.html」存儲在我的assets/html /目錄中,並且此html加載自定義字體(存儲在assets/fonts /下)如下:在Android 4.2(API 17)中加載自定義字體的問題

<style type="text/css"> 
    @font-face { 
     font-family: 'MyFont'; 
     src: url('file:///android_asset/fonts/myfont.ttf'); 
    } 
</style> 

我使用下面的代碼加載這個網站:

String html = getHtml(); // This method loads the myhtml.html from asset. This loads properly. 
WebView webView = (WebView) findViewById(R.id.webbox); 
WebSettings webSettings = webView.getSettings(); 
webSettings.setDefaultTextEncodingName("utf-8"); 
webSettings.setFixedFontFamily("fonts/myfont.ttf"); 
webView.loadDataWithBaseURL("file:///android_asset/", html, "text/html", "UTF-8", null); 

此代碼工作正常所有的Android版本的Android除外4.2(API 17)。

在Android 4.2中,加載了HTML,但未加載自定義字體。

+1

同樣的問題在這裏 – 2013-03-20 06:13:07

+0

事實上,這用於API 17工作。我懷疑它是與最新的補丁更新中斷。 – Christopher 2013-04-18 19:03:20

+0

同樣的問題在這裏。 – 2013-05-15 16:23:17

回答

1

請使用(svg字體)。它適用於我

0

我有同樣的問題。更改

webView.loadDataWithBaseURL("file:///android_asset/", html, "text/html", "UTF-8", null); 

webView.loadDataWithBaseURL("http://example.com", html, "text/html", "UTF-8", null); 

修復該問題。