Click a hyperlink in the android WebView application and do not call the system browser.

Source: Internet
Author: User

Click a hyperlink in the android WebView application and do not call the system browser.
Public class MainActivity extends Activity {


Private WebView mWebView;


@ Override
Public void onCreate (Bundle savedInstanceState ){
Super. onCreate (savedInstanceState );
SetContentView (R. layout. activity_main );
MWebView = (WebView) findViewById (R. id. webview );


WebSettings setting = mWebView. getSettings ();
Setting. setPluginState (PluginState. ON );
Setting. setJavaScriptEnabled (true );
MWebView. setScrollBarStyle (0 );

// Rewrite the shouldOverrideUrlLoading () method of WebViewClient

// If event processing is required, false is returned; otherwise, true is returned. This solves the problem.

MWebView. setWebViewClient (new WebViewClient (){
@ Override
Public boolean shouldOverrideUrlLoading (WebView view, String url ){
Lodurl (view, url );
Return false;
}
});

This. mWebView. loadUrl (http: // 192.168.1.59/assets/widget /);


}


Public void lodurl (final WebView webView, final String url ){
New Thread (new Runnable (){
@ Override
Public void run (){
WebView. loadUrl (url );
}
});
}
}

 

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.