1

1画面に2つのWebサイトを表示できるwebviewアプリを作ろうとしています。しかし、アプリを実行すると、1 つの Web サイトが表示され、新しいブラウザーで開きます。どうすれば 2 つの Web サイトを表示できますが、新しいブラウザーでは機能しませんか? これは私の WebViewActivity クラスです:

    package com.mkyong.android;

    import android.app.Activity;
    import android.os.Bundle;
    import android.webkit.WebView;

   public class WebViewActivity extends Activity {

    private WebView webView1, webView2;

    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.webview);

        webView1 = (WebView) findViewById(R.id.webView1);
        webView1.getSettings().setJavaScriptEnabled(true);
        webView1.loadUrl("http://www.google.com");
        webView2 = (WebView) findViewById(R.id.webView2);
        webView2.getSettings().setJavaScriptEnabled(true);
        webView2.loadUrl("http://www.google.com");



    }

 }

これは私のxmlファイルです:

     <?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:orientation="vertical" >


    <WebView
        android:id="@+id/webview1"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_weight="0.39" />


    <WebView
        android:id="@+id/webview2"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_weight="0.53" />

  </LinearLayout>
4

1 に答える 1

0

framelayout を使用し、webviewClient を webview に設定することをお勧めします

この関数 shouldOverrideUrlLoading (webviewClient の宣言内)

@Override
             public boolean shouldOverrideUrlLoading(WebView view, String url) 
            {
                Log.i("Page", url);
                view.setWebViewClient(new MyWebViewClient());
                view.setWebChromeClient(new MyWebChromeClient());
                view.loadUrl(url);
                return true;
            }

WebView によって読み込まれた URL を上書きし、新しいブラウザではなく WebView に読み込まれるように強制します

于 2012-11-14T11:24:28.293 に答える