2013-10-11 42 views
0

我創建一個web視圖的應用程序。我在資產文件夾中添加了字體。我正在使用CSS代碼來使其工作。但是字體沒有加載到webview中。 Unicode塊沒有顯示在我的webview應用程序中。鏈接:http://en.wikipedia.org/wiki/Lisu_(Unicode_block) 這裏是我現在使用的代碼。添加字體到網頁視圖

@Override 
protected void onCreate(Bundle savedInstanceState) { 
    super.onCreate(savedInstanceState); 
    setContentView(R.layout.activity_webview); 
    String html = "<html><head><style>@font-face {@font-family: 'Conv_LISU'; src: url('file:///android_asset/font/LISU.ttf');} body, button, input, label, select, td, tr, textarea,li,ul,span,div,table,h1,h2,h3,h4{ font-family:Conv_LISU;}</style></head>"; 

    WebView webView = (WebView)findViewById(R.id.webView); 
    webView.setWebViewClient(new WebViewClient() { 
     @Override 
     public void onReceivedError(WebView view, int errorCode, 
       String description, String failingUrl) { 
      // Handle the error 
     } 

     @Override 
     public boolean shouldOverrideUrlLoading(WebView view, String url) { 
      view.loadUrl(url); 
      return true; 
     } 
    }); 

    webView.setInitialScale(1); 
    webView.getSettings().setJavaScriptEnabled(true); 
    webView.getSettings().setLoadWithOverviewMode(true); 
    webView.getSettings().setUseWideViewPort(true); 
    webView.setScrollBarStyle(WebView.SCROLLBARS_OUTSIDE_OVERLAY); 
    webView.setScrollbarFadingEnabled(false); 
    webView.loadData(html, "text/html", "utf-8"); 
    webView.loadUrl("http://google.com"); 


} 

}

+0

究竟什麼是你的問題的WebView? –

+0

的字體沒有加載到web視圖和Unicode塊沒有在網頁視圖出現。 –

回答

0

加載另一個URL會抹去你先放入Web視圖中的HTML內容,因此CSS樣式。

我認爲你可以做到這一點無論是使用JavaScript的觀點被加載後,注入它view.loadUrl("javascript:script to apply css here")的唯一途徑。

或者你也可以手動下載請求的HTML頁面,注入CSS代碼,然後將其送入將加載資產原始網頁以及:)

+0

我會嘗試一下 –