-1

Web ビューでヒンディー語フォントを含む URL をロードする必要がある Android アプリケーションを開発しています。

これには次のコードを使用しました。

WebView webView = (WebView) findViewById(R.id.webView);

WebSettings settings = webView.getSettings();
settings.setJavaScriptEnabled(true);
settings.setBuiltInZoomControls(true);
settings.setSupportZoom(true);
settings.setDefaultTextEncodingName("utf-8");

webView.setScrollBarStyle(WebView.SCROLLBARS_OUTSIDE_OVERLAY);
webView.getSettings().setLoadWithOverviewMode(true);
webView.getSettings().setUseWideViewPort(true);
webView.loadUrl(url);

このコードは、最新のデバイスのほとんどで正常に動作し、ヒンディー語のコンテンツを適切に表示します。 ただし、Android 2.2、2.3、またはその他の下位バージョンでは、ヒンディー語ではなくボックスが表示されます。

アプリケーションをすべてのデバイスで実行できるように、英語以外のテストで Web ビューを有効にする方法を教えてください。

前もって感謝します...

4

2 に答える 2

1

以下のリンクを試してください:ここをクリック

private boolean copyFile(Context context,String fileName) {
        boolean status = false;
        try { 
            FileOutputStream out = context.openFileOutput(fileName, Context.MODE_PRIVATE);
            InputStream in = context.getAssets().open(fileName);
            // Transfer bytes from the input file to the output file
            byte[] buf = new byte[1024];
            int len;
            while ((len = in.read(buf)) > 0) {
                out.write(buf, 0, len);
            }
            // Close the streams
            out.close();
            in.close();
            status = true;
        } catch (Exception e) {
            System.out.println("Exception in copyFile:: "+e.getMessage());
            status = false;
        }
        System.out.println("copyFile Status:: "+status);
        return status;
    }

3.上記の関数を一度だけ呼び出す必要があります(これにはいくつかのロジックを見つける必要があります)。

copyFile(getContext(), "myfont.ttf");

4.以下のコードを使用して、webview の値を設定します。ここでは CSS を使用してフォントを設定しています。

private String getHtmlData(Context context, String data){
    String head = "<head><style>@font-face {font-family: 'verdana';src: url('file://"+ context.getFilesDir().getAbsolutePath()+ "/verdana.ttf');}body {font-family: 'verdana';}</style></head>";
    String htmlData= "<html>"+head+"<body>"+data+"</body></html>" ;
    return htmlData;
 }

5.上記の関数を以下のように呼び出すことができます

webview.loadDataWithBaseURL(null, getHtmlData(activity,htmlData) , "text/html", "utf-8", "about:blank");

于 2013-08-09T08:24:34.043 に答える