0

我有一个 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

    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而不调用默认浏览器

4

1 回答 1

0

您需要实现您的网络客户端并将其设置为您的 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 在调用 loadurl 时启动浏览器

于 2013-04-10T14:23:26.597 回答