开发者

Control the Link in WebView in android?

I have loaded an url in WebView in android, when i click a link in that loaded url in WebView , the link loaded in WebView ugly, to remove this problem I had used setIntialScale(50) , this made my initial url beco开发者_运维百科mes small


Works like a charm. Check it out

webview.setWebViewClient(new WebViewClient() {

     public boolean shouldOverrideUrlLoading(WebView view, String url) {
          return true; 
     }
});


I am not sure but i think you need to implement WebViewClient.

For example:

  webview.setWebViewClient(new WebViewClient() {
            public boolean shouldOverrideUrlLoading(WebView view, String url) {
                Log.i(TAG, "Processing webview url click...");
                view.loadUrl(url);
                return true;
            }

            public void onPageFinished(WebView view, String url) {
                Log.i(TAG, "Finished loading URL: " +url);
                if (progressBar.isShowing()) {
                    progressBar.dismiss();
                }
            }

            public void onReceivedError(WebView view, int errorCode, String description, String failingUrl) {
                Log.e(TAG, "Error: " + description);
                alertDialog.setTitle("Error!! Something went wrong");
                alertDialog.setMessage(description);
                alertDialog.setButton("OK", new DialogInterface.OnClickListener() {
                    public void onClick(DialogInterface dialog, int which) {
                        return;
                    }
                });
                alertDialog.show();
            }
        });
        webview.loadUrl("http://www.google.com");


When you click the link, the phone is opening the new page in the browse instead of your webview. If you disable Url Overriding all subsequent pages will load in the webview and preserve the zoom.

webview.setWebViewClient(new WebViewClient() {

     public boolean shouldOverrideUrlLoading(WebView view, String url) {
          return false; 
     }
});
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜