android webview自定义字体不会工作?

时间:2014-02-02 12:18:28

标签: android webview

我尝试在我的网页浏览中添加自定义字体,但它根本不起作用 我已经关注并尝试了stackoverfolow中的每个答案,但它仍然没有工作

这是我的代码:

 holder.postbit_message.loadDataWithBaseURL("file:///android_asset/",aHtml.output(post.pagehtml), 
                                        "text/html",
                                        "UTF-8","null");

这是输出:

String global_css = "@font-face {font-family: 'almdroid';src: url('fonts/neu.ttf'); } "+
                    "body,html{font-family: 'almdroid';font-size: 10pt; word-wrap: break-word;} "+
                    "img{margin : 2px;} "+ 
                    "img.youtbe_img{padding: 2px;border : 1px solid #dfdfdf;background-color : #ebebeb;margin : 3px;}"+
                    "a {text-decoration: none;color: #0066CC}"+
                    "fieldset{word-wrap:break-word;font-size: 9pt;border : 1px solid #e6e6e6;margin : 10px 0;color: #636363;background-color: #f6f6f6;padding:5px;}"+
                    "legend{font-size: 9pt;border : 1px solid #e6e6e6;padding: 4px 5px;background-color : #ffffff;color : #6a6a6a;}"+
                    "img,legend,fieldset{-webkit-border-radius: 5px 5px 5px 5px;border-radius: 5px 5px 5px 5px;}"+
                    "img.effect_me{-webkit-box-shadow: 0 0 1px 1px #b2b2b2;box-shadow: 0 0 1px 1px #b2b2b2;}";

1 个答案:

答案 0 :(得分:0)

从我需要在WebView中更改字体的项目

holder.postbit_message.loadDataWithBaseURL(null,
    "<html><style type=\"text/css\">" +
    "@font-face {font-family: MyFont; font-style: bold; src: url(\"file:///android_asset/font/Roboto-Light.ttf\")} " + "body { font-family: MyFont; font-size: medium; text-align: justify; color: black;}</style><body>" +
    yourText +
    "</body></html>", "text/html", "utf-8", null);