android use webview to load webpage problem

When I am making a picture station http://www.mimi199.com, I want to package its mobile station into an app.

I use webview to load the web page (I wanted to use phonegap to do it, but it is still too troublesome), the

specific code 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 , the homepage effect is good, but there is a problem, when a hyperlink is clicked, the app will automatically call the browser to open a new page, which is not the function I want, What I hope is that each page should be opened in the app when it is opened, and the browser is closed!

After checking a lot of information, it turns out that there is also a class of WebviewClient.

Just write another class to become WebviewClient. The

code is as follows



public class MyWebViewClient extends WebViewClient {
    public boolean shouldOverrideUrlLoading(WebView webView,String url){
        webView.loadUrl(url );//This is the sentence, let each hyperlink open in the app's webview instead of the browser
        return true;
    }
}
Then change it slightly MainActivity

    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
WebView webView=new WebView(this);
        webView.loadUrl("http://www.mimi199.com/);
//Add this sentence It
        's ok webView.setWebViewClient(new MyWebViewClient());

     }
android beginners share with you

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=326129310&siteId=291194637