android webview留在应用程序中 [英] android webview stay in app

查看:24
本文介绍了android webview留在应用程序中的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我的 android 应用中有一个 webview,但是当有人浏览网站时,它会在一个新窗口中打开,我希望它留在 webview 中..有没有办法轻松做到这一点?这是我的活动中的代码:

I have a webview in my android app, but when someone navigates around the site, it opens in a new window, i want it to stay inside the webview.. is there a way to do this easily? Here is the code in my activity:

super.onCreate(savedInstanceState);
    setContentView(R.layout.shop);
    WebView webview;
    webview = (WebView) findViewById(R.id.webview);
    webview.getSettings().setJavaScriptEnabled(true);
    webview.loadUrl("http://www.google.co.uk");

推荐答案

您必须创建一个 WebViewClient:

public class myWebViewClient extends WebViewClient {
    @Override
    public boolean shouldOverrideUrlLoading(WebView view, String url) {
        view.loadUrl(url);
        return true;
    }
}

然后将其设置为您的 WebView,如下所示:

And then set it to your WebView like this:

webview.setWebViewClient(new myWebViewClient());

这篇关于android webview留在应用程序中的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆