Android 5.0上的Webview不显示组合框内容

时间:2015-03-24 07:55:15

标签: android webview

我用webview写了一个应用程序。当我在Android 4.4或更低版本上运行时,我的应用程序运行正常。但是当在Android 5.0上运行它时,我的webview不会在屏幕截图中显示组合框的内容。当我使用webrowser默认的android时,它加载我的网络正常。

当我运行我的应用程序时 enter image description here

当我使用android 5.0的webrowser默认值时。 enter image description here

我的代码:

private WebView webPos;

@Override
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.main);
    progressDialog = new ProgressDialog(this);
    webPos = (WebView) findViewById(R.id.webPos);
    CookieSyncManager.createInstance(this);
    CookieSyncManager.getInstance().startSync();
    try {
        version = getPackageManager().getPackageInfo(getPackageName(), 0).versionName;
        CallUrl wst = new CallUrl(CallUrl.GET_TASK, this,version);
        String Server = "http://androidquery.appspot.com/api/market?app=longvan.mobile.softflowspos";
        wst.execute(new String[] {
                Server
        });
        webPos.setWebChromeClient(new WebChromeClient() {

            @Override
            public void onProgressChanged(WebView view, int newProgress) {
                progressDialog.setMessage("Đang tải..." + newProgress + "%");
                //Log.i("Url hiện tại là: ", webPos.getUrl());
            }
        });

        webPos.setWebViewClient(new WebViewClient() {
            @Override
            public void onPageFinished(WebView view, String url) {
                super.onPageFinished(view, url);
                progressDialog.dismiss();
            }

            @Override
            public void onPageStarted(WebView view, String url, Bitmap favicon) {
                super.onPageStarted(view, url, favicon);
                progressDialog.setCancelable(false);
                progressDialog.show();
            }

            public void onReceivedError(WebView webView, int errorCode, String description, String failingUrl) {
                Log.i("Error Web View Client: ", description);
                Alert alert = new Alert(SoftflowsPos.this, "Server đang bảo trì. Ứng dụng sẽ tạm thời đóng ngay bây giờ.");
                alert.showAlert();
            }
        });
        webPos.getSettings().setJavaScriptEnabled(true);
        webPos.getSettings().setJavaScriptCanOpenWindowsAutomatically(true);
        webPos.getSettings().setSavePassword(true);
        webPos.getSettings().setLoadsImagesAutomatically(true);
        webPos.getSettings().setDatabaseEnabled(false);
        webPos.getSettings().setDomStorageEnabled(true);
        webPos.getSettings().setLoadWithOverviewMode(true);
        webPos.getSettings().setUseWideViewPort(false);
        webPos.getSettings().setSupportZoom(false);
        webPos.getSettings().setBuiltInZoomControls(false);
        webPos.getSettings().setDisplayZoomControls(false);
        webPos.getSettings().setCacheMode(WebSettings.LOAD_NO_CACHE);
        webPos.getSettings().setRenderPriority(WebSettings.RenderPriority.HIGH);
        webPos.getSettings().setAppCacheEnabled(false);
        webPos.setScrollBarStyle(WebView.SCROLLBARS_OUTSIDE_OVERLAY);
        webPos.setScrollbarFadingEnabled(true);
        webPos.setFocusable(true);
        webPos.setInitialScale(100);
        if (Build.VERSION.SDK_INT >= 19) {
            webPos.setLayerType(View.LAYER_TYPE_HARDWARE, null);
        } else {
            webPos.setLayerType(View.LAYER_TYPE_SOFTWARE, null);
        }
        TestConnect testConnect = new TestConnect();
        Boolean flag = testConnect.execute(urlTest).get();
        if (isNetwworkAvailable() == true) {
            if (flag == true) {
                if (savedInstanceState != null) {
                    webPos.restoreState(savedInstanceState);
                } else {

                    webPos.loadUrl(urlServer);
                }
            } else {
                Alert alert = new Alert(this, "Server đang bảo trì. Ứng dụng sẽ đóng ngay bây giờ.");
                alert.showAlert();
            }
        } else {
            Alert alert = new Alert(this, "Thiết bị của bạn chưa có kết nối mạng. Ứng dụng sẽ đóng ngay bây giờ.");
            alert.showAlert();
        }
    } catch (PackageManager.NameNotFoundException e) {
        e.printStackTrace();
        Log.i("Thông tin version bị lỗi: ", e.toString());
    } catch (InterruptedException e) {
        e.printStackTrace();
        Log.i("Kiểm tra kết nối bị lỗi: ", e.toString());
    } catch (ExecutionException e) {
        e.printStackTrace();
    }
}

0 个答案:

没有答案