WebView没有填充

时间:2013-04-10 14:06:30

标签: android android-layout android-webview

我有一个TextView打开另一个带有webview的布局。我希望webview填充http://m.twitter.com

然而,当单击textview时,它会打开布局,然后调用浏览器而不是填充webview。

带有textview的原始布局: -

      <TextView
      android:id="@+id/GoToTCContacting"
      android:layout_width="360dp"
      android:layout_height="wrap_content"
      android:layout_marginLeft="2dp"
      android:layout_marginRight="2dp"
      android:layout_weight="2"
      android:background="@drawable/border2"
      android:clickable="true"
      android:onClick="GoToTCContacting"
      android:padding="10dp"
      android:text="Contacting"
      android:textColor="#FFF"
      android:textSize="18sp" />   

使用WebView的目标布局(t_c_contacting)

      <WebView
      android:id="@+id/TCcontactingView"
      android:layout_width="match_parent"
      android:layout_height="match_parent" />

Java for function

    public void GoToTCContacting(View view)  
{  
    setContentView(R.layout.t_c_contacting); 
    WebView webView =   (WebView)findViewById(R.id.TCcontactingView);
    webView.loadUrl("http://m.twitter.com");
}

如何让它填充webview而不是调用默认浏览器

1 个答案:

答案 0 :(得分:0)

您需要实现Web客户端并将其设置为WebView:

webView.setWebViewClient(new MyWebViewClient());

private class MyWebViewClient extends WebViewClient {
        @Override
        public boolean shouldOverrideUrlLoading(WebView view, String url) {
            view.loadUrl(url);
            return true;
        }
    }

示例:http://marakana.com/forums/android/examples/58.html

重复:Android webview launches browser when calling loadurl