Mahek Mahek - 3 months ago 12
Android Question

Link should be open in same web view in Android

I am new in Android and I am trying to open a Link in webview using this code

WebView myWebView = (WebView) findViewById(R.id.webinfo);
myWebView.loadUrl("http://oslobokfestival.netteam.no/artical.php?articalid=93");
myWebView.setBackgroundResource(R.drawable.lbg);
myWebView.setBackgroundColor(Color.TRANSPARENT);
myWebView.getSettings().setJavaScriptEnabled(true);


and in this HTML page contains some links and I want that when user click that link should be open in same webview,
at this point its opening in mobile browser, please give me appropriate solution..
Thanks.

Answer

You need to add WebViewClient to your WebView in order to open it in the WebView. Something like


    myWebView.setWebViewClient(new WebViewClient() {
        @Override
        public boolean shouldOverrideUrlLoading(WebView view, String url) {
            view.loadUrl(url);
            return false;
        }
    });