2

私は多くのhtmlページを持つアプリケーションに取り組んでいます。これらはEclipseのrawフォルダーに作成しました。

多くのhtmlファイルを作成する予定ですが、各htmlファイルで呼び出すcssファイルの場所を1つだけにします。このアプリケーションは、loadDataメソッドが次のようにhtmlページを表示するように機能します。

webview.loadData(readTextFromResource(R.raw.gen1), "text/html", "utf-8");

どんなアイデアでもありがたいです。

4

1 に答える 1

6

以下のコードのように、プロジェクトアセット内のhtmlファイルとcssファイルをコピーし、アセットからwebviewにhtmlファイルをロードできます。

    WebView wv;  
    wv = (WebView) findViewById(R.id.webView1);  
    wv.setBackgroundColor(0);
    wv.setBackgroundResource(android.R.color.black);
    wv.setWebChromeClient(new WebChromeClient());
    wv.setWebViewClient(new WebViewClient());
    wv.getSettings().setJavaScriptEnabled(true);
    wv.getSettings().setPluginsEnabled(true);
    wv.loadUrl("file:///android_asset/Index_Animation/test.html");

以下のスクリーンショットのように:

ここに画像の説明を入力してください

以下のhtmlファイルでcssを参照してください。

<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html><head><meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<link rel="stylesheet" href="./style.css" type="text/css" media="screen"><!--This line refer the css file-->

  </head>
    <body bgcolor="#000000">        

                <div class="col_left">
                    <div class="logo">
                        <div class="circles">
                            <div class="circle"></div>
                            <div class="circle1"></div>
                            <div class="circle2"></div>
                        </div>
                        <center>
                        <img src="./Untitled.png" />
                        </center>
                    </div>

                </div>

</body></html>
于 2012-06-26T09:31:48.770 に答える