1

我正在尝试制作一个可以在一个屏幕上显示两个网站的 webview 应用程序。但是当我运行我的应用程序时,它会显示一个网站并在新浏览器上打开。我怎样才能显示两个网站,但它在新浏览器上不起作用?这是我的 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

I suggest you use framelayout and try to set webviewClient to your webview

this function shouldOverrideUrlLoading (in the declaration of the 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;
            }

will override url loaded by the webview and force it to be loaded in the webview not in the new browser

于 2012-11-14T11:24:28.293 回答