2

HTML を Android に統合しています。Web ビューを作成しましたが、ローカルの HTML ページを読み込めません。驚いたことに、Web ビューはローカルの html ファイルではなく、「http:google.com」を正しく読み込んでいます。SOのほぼすべての可能なリンクを試しました。エラー メッセージは「Web ページを読み込めませんでした」です。

WebView view  =  (WebView) findViewById(R.id.webView1);
    view.loadUrl("file:///assets/www/trialhtml.html");![enter image description here][1]
4

4 に答える 4

7

Create your HTML file and place it in the assets folder, then you need to add these lines to the onCreate method like this:

public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    WebView webView = new WebView(this);
    webView.loadUrl("file:///android_asset/test.html");
    setContentView(webView);
}

Here is the final result: App Screenshot

于 2013-02-08T08:04:13.443 に答える
0

.html ファイルをプロジェクト フォルダーの assets フォルダーに貼り付けます。folコードを使用してレイアウトフォルダーにxmlファイルを作成します

WebView  xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/webview"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
/>

アクティビティに fol コードを追加

setContentView(R.layout.my);
WebView mWebView = null;
mWebView = (WebView) findViewById(R.id.webview);
mWebView.getSettings().setJavaScriptEnabled(true);
mWebView.loadUrl("file:///android_asset/www/trialhtml.html"); //new.html is html file na
于 2013-02-08T07:54:45.300 に答える
0

以下のコードを試してください:-

public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.main);
    String myURL = "file:///android_asset/index.html";
    WebView view  =  (WebView) findViewById(R.id.webView1);

    /*By default Javascript is turned off,
     * it can be enabled by this line.
     */
    view.getSettings().setJavaScriptEnabled(true);
    view.setWebViewClient(new WebViewClient());

    view.loadUrl(myURL);

}

ur ファイルが存在するかどうかを確認し、プロジェクトを消去して再構築することもできます。

于 2013-02-08T07:49:43.503 に答える
0

このコードを使用してみてください:

this.webview = (WebView)findViewById(R.string.webview);

    WebSettings settings = webview.getSettings();
    settings.setJavaScriptEnabled(true);
    webview.setScrollBarStyle(WebView.SCROLLBARS_OUTSIDE_OVERLAY);

    final AlertDialog alertDialog = new AlertDialog.Builder(this).create();

    progressBar = ProgressDialog.show(Main.this, "WebView Example", "Loading...");

    webview.setWebViewClient(new WebViewClient() {
        public boolean shouldOverrideUrlLoading(WebView view, String url) {
            Log.i(TAG, "Processing webview url click...");
            view.loadUrl(url);
            return true;
        }

        public void onPageFinished(WebView view, String url) {
            Log.i(TAG, "Finished loading URL: " +url);
            if (progressBar.isShowing()) {
                progressBar.dismiss();
            }
        }

        public void onReceivedError(WebView view, int errorCode, String description, String failingUrl) {
            Log.e(TAG, "Error: " + description);
            Toast.makeText(activity, "Oh no! " + description, Toast.LENGTH_SHORT).show();
            alertDialog.setTitle("Error");
            alertDialog.setMessage(description);
            alertDialog.setButton("OK", new DialogInterface.OnClickListener() {
                public void onClick(DialogInterface dialog, int which) {
                    return;
                }
            });
            alertDialog.show();
        }
    });
    webview.loadUrl("http://www.google.com");
于 2013-02-08T07:50:22.930 に答える