的WebView在Android的触发标准的浏览器浏览器、标准、WebView、Android

由网友(以后别单纯)分享简介:我已经显示的网站创建于Android的一个活动。我用这个code:I have created an Activity in Android for displaying websites. I used this code: private WebView mWebview; @Overrideprotecte...

我已经显示的网站创建于Android的一个活动。我用这个code:

I have created an Activity in Android for displaying websites. I used this code:

private WebView mWebview; 

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    this.requestWindowFeature(Window.FEATURE_NO_TITLE);
    this.getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN, WindowManager.LayoutParams.FLAG_FULLSCREEN);
    mWebview = new WebView(this);
    mWebview.getSettings().setJavaScriptEnabled(true); // enable javascript
    mWebview.loadUrl("http://blablabla");
    CookieSyncManager.createInstance(this);
    CookieManager cookieManager = CookieManager.getInstance();
    cookieManager.removeAllCookie();
    setContentView(mWebview);

但是,当我使用它,例如www.bild.de,或它的移动版本wap.bild.de,它触发标准的浏览器,并从我的应用程序失控。同样的,如果我点击来自网站的链接。我不希望出现这种情况。我究竟做错了什么?谢谢你。

But when I use it with for example www.bild.de, or its mobile version wap.bild.de, it fires the standard browser and gets out from my app. The same if I tap a link from that website. I don't want that. What am I doing wrong? Thanks.

推荐答案

我只是跑你code。在我的手机上测试项目,似乎加载的第一页时正常工作。它装载wap.bild.de而不首次出现任何问题。

I just ran your code in a test project on my phone and it seems to work perfectly when loading the first page. It loaded wap.bild.de without any problems for the first time.

我做到了,但经验的默认浏览器,当我点击一个链接推出了同样的问题。为了解决这个问题,只需加上下面几行:

I did, however, experience the same problem that the default browser is launched when I tap on a link. To fix that, just add the following lines:

mWebview.setWebViewClient(new WebViewClient() {
        @Override
        public boolean shouldOverrideUrlLoading(WebView view, String url) {
            view.loadUrl(url); // open link in the same web view.
            return true;
        }
    });
阅读全文

相关推荐

最新文章