2012-11-14 24 views
0

我正在試圖製作一個webview應用程序,它可以在一個屏幕中顯示兩個網站。但是當我運行我的應用程序時,它會顯示一個網站並在新瀏覽器上打開。我怎樣才能顯示兩個網站,它不適用於新的瀏覽器? 這是我WebViewActivity類:在一個屏幕中顯示兩個webview

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> 

回答

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加載的網址並強制它在web瀏覽器中加載而不是在新瀏覽器中

相關問題