Android uses WebView to load Web page problems

Source: Internet
Author: User

I'm doing a picture station http://www.mimi199.com to pack its mobile station into an app,

I used WebView to load the Web (I wanted to use PhoneGap to do it, but it was too much trouble),

The specific code is as follows:



protected void OnCreate (Bundle savedinstancestate) {
super.oncreate (savedinstancestate);
WebView webview=new WebView (this);
Webview.loadurl ("http://www.mimi199.com/");

Intent intent= getintent ();
Setcontentview (webView);
    } 
done

Wait, home effect is good, but there is a problem, when clicked on a hyperlink, the app will automatically call the browser to open a new page, this is not the function I want, I want to open the time should be every page in the app open, close browser God horse!

looked up a lot of information, there is a webviewclient class

just write another class to be webviewclient.

The code is as follows

Public class Mywebviewclient extends Webviewclient {
Public Boolean shouldoverrideurlloading (WebView webview,string url) {
webview.loadurl (URL);//This is the phrase, let each hyperlink in the app's WebView open, not the browser
return true;
    } 

and change the mainactivity a little bit .

protected void OnCreate (Bundle savedinstancestate) {
super.oncreate (savedinstancestate);
WebView webview=new WebView (this);
Webview.loadurl ("http://www.mimi199.com/");
//Multiple plus this sentence will be all right
webview.setwebviewclient (New Mywebviewclient ());

     } 
Android Beginner with everyone

This article is from the "Yang Technical column" blog, please be sure to keep this source http://13438626.blog.51cto.com/13428626/1980440

Android uses WebView to load Web page problems

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.