Home > Blockchain >  get content html page with web view in android
get content html page with web view in android

Time:10-09

I am working on an Android project in which I am loading an HTML page from the internet, not locally and then displaying it in WebView. It works fine, but unfortunately, when I click on any of the element in WebView, it opens the link in Browser.

What changes do I need to make so that any links clicked within the web-view will be opened by Web-view itself. Thank you.

public class ContainerActivity extends Activity {
    private WebView mWebView;

    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.contain);

        mWebView = (WebView)findViewById(R.id.wvPortal);
        mWebView.loadUrl("www.domain.com/path/to/index.html");
        WebSettings mWebSettings = mWebView.getSettings();
        mWebSettings.setJavaScriptEnabled(true);
    }
}

CodePudding user response:

Try to use setWebViewClient:

mWebView = (WebView)findViewById(R.id.wvPortal);
mWebView.setWebViewClient(new WebViewClient());
mWebView.loadUrl("www.domain.com/path/to/index.html");
  • Related