Android WebView找不到kitkat和棒棒糖的预期效果

时间:2015-04-13 15:17:23

标签: android webview

我已经使用了webview并且它的工作正常但是我需要在webview中找到一些文本。它工作到api级别18但是在它已经弃用之后,所以我想知道有没有办法找出这个问题并解决这个问题问题。任何机构有任何想法然后请帮助我解决这个问题。我感谢你的帮助

1 个答案:

答案 0 :(得分:1)

我不确定这是不是问题,但你应该在其他所有事情之后最后调用loadUrl。 此外,您似乎使用shouldOverridemethod循环您的webview,检查我的版本

    webviewdevelopment = (WebView) findViewById(R.id.webViewdevelopment);
    webviewdevelopment.setWebViewClient(new myWebClient());
    webviewdevelopment.getSettings().setJavaScriptEnabled(true);
    webviewdevelopment.loadUrl("http://stackoverflow.com");

public class myWebClient extends WebViewClient {
    @Override
    public void onPageStarted(WebView view, String url, Bitmap favicon) {
        super.onPageStarted(view, url, favicon);
    }

    @Override
    public boolean shouldOverrideUrlLoading(WebView view, String url) {

        Uri uri;

        try {
            uri = Uri.parse(url);
        } catch (NullPointerException e) {
            // let Android deal with this
            return true;
        }

        String host = uri.getHost(); //Host is null when user clicked on email, phone number, ...

        if (host != null && host.equals("stackoverflow.com")) {
            // This is my web site, so do not override; let my WebView load the page.  
            return false;
        }
        else {
            // You should consider this, since you are using JavaScript.. you may make your users vulnerable 
            // Otherwise, the link is not for a page on my site, so launch another Activity that handles URLs or anything else (email, phone number, ...)
            Intent intent = new Intent(Intent.ACTION_VIEW, Uri.parse(url));
            startActivity(intent);
            return true;
        }

    }
}