开发者

WebView clicks opens mobile browser

There is a WebView whic开发者_开发技巧h loads mobile-optimized URL (webpage). But when I click on a link, it does not load inside of the WebView (inside of the app), but mobile browser opens.

How to prevent this?

I tried overloading URLs via shouldOverrideUrlLoading(), but it did not help.

This is a code.

webView = (WebView) findViewById(R.id.webview);
WebSettings webSettings = webView.getSettings();
webSettings.setPluginsEnabled(true);
if (Build.VERSION.SDK_INT > 7) {
    webSettings.setPluginState(WebSettings.PluginState.ON);
}
webSettings.setJavaScriptEnabled(true);
webView.setWebViewClient(new WebViewClient() {
    @Override
    public boolean shouldOverrideUrlLoading(WebView view, String url) {
        if (url.equals(url)) {
            view.loadUrl(url);
            return true;
        }
        return false;
    }


    @Override
    public void onLoadResource(WebView view, String url) {
    }
});
webView.loadUrl("http://some-url.com");

EDIT

Does GET or POST posting methods have anything with links' clicks open mobile web browser???


Return true instead of false in shouldOverrideUrlLoading.

From the documentation:

shouldOverrideUrlLoading returns True if the host application wants to leave the current WebView and handle the url itself, otherwise return false.

0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜