2012-08-06 77 views
0

我目前正在開發一個Android網頁瀏覽器。有一些頁面使用其他字符如維吾爾字符,並且它們顯示不正常,所以我使用下面的代碼來解決這個問題。後webview使用自定義字體

String htmlStr = getHTML(url, "UTF-8");//get the html content from the url 

    String tmp="<link href=\"file:///android_asset/myfont.css\" rel=\"stylesheet\" type=\"text/css\" />"; 

    if(htmlStr.contains("</head>")){ 
     htmlStr = htmlStr.replace("</head>", tmp);//add my css into the page 
    } 

mCurrentWebView.loadDataWithBaseURL(url, htmlStr,"text/html", "utf-8", "");//display the page content 

這是myfont.css:

@font-face { font-family: MyCustomFont; src: url("fonts/ALPEKRAN.TTF") } 
body {font-family: MyCustomFont, Verdana, Arial, sans-serif; text-align:right;} 

的ALPEKRAN.TTF字體的資產/字體/文件夾之下。

但還有像頁面css丟失的另一個問題。 請給我一些建議。

回答

0

願你需要指定完整的字體鏈接,請嘗試:

src: url("file:///android_asset/fonts/ALPEKRAN.TTF")