Android 4.2.2和4.4.2之间的webview.loadURL发生了哪些变化

时间:2014-08-18 22:52:07

标签: android html webview

我有一个应用程序加载一个网站的一部分,其中包含一些基于汽车牌照的JavaScript。该页面在三星Galaxy s4上显示为Android 4.2.2而不是4.4.2当我用Android 4.4.2测试应用程序时显示的是document.body.style.minWidth,即webview显示文本:300px

我浪费了很多时间盯着盲人,所以任何提示或帮助都非常受欢迎!

代码是这样的:

@Override
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.webview);

    ((Button)findViewById(R.id.btnBack)).setVisibility(View.VISIBLE);

    wv = (WebView) findViewById(R.id.wv);
    reg = getIntent().getStringExtra("reg");

    Typeface tf = Typeface.createFromAsset(getAssets(), "font.ttf");
    ((TextView)findViewById(R.id.title)).setTypeface(tf);
    ((TextView)findViewById(R.id.title)).setText("Motorregister - (DMR)");

    wv.getSettings().setJavaScriptEnabled(true);
    wv.setWebViewClient(new WebViewClient() {
        private ProgressDialog pd;
        private int count = 0;

        @Override
        public void onPageFinished(WebView view, String url) {
            if (count==1) {
                view.loadUrl("javascript:document.getElementById('regnr').checked=true;"
                        +"document.getElementById('soegeord').value='"+reg+"';"
                        +"document.getElementById('searchForm').submit();"
                        +"DMR.WaitForLoad.on();");
            } else if (count>=2) {
                view.loadUrl("javascript:document.body.innerHTML " +
                        "= '<div class=\"tabNav\">'+document.getElementsByClassName('tabNav')[0].innerHTML+'</div>';" +
                        "document.getElementsByClassName('h-tab-content')[0].style.width='320px';" +
                        "document.getElementsByClassName('h-tab-btns')[0].style.width='320px';" +
                        "document.getElementsByClassName('h-tab-btns')[0].style.height='45px';" +
                        "document.getElementsByTagName('ul')[0].style.display='inline';" +
                        "document.head.appendChild='<meta name=\"viewport\" content=\"width=device-width\">';" +
                        "document.body.style.minWidth ='300px';");
                if (pd!=null) {
                    pd.dismiss();
                }
                view.setVisibility(View.VISIBLE);
            }
        }

        @Override
        public void onPageStarted(WebView view, String url, Bitmap favicon) {
            if (pd==null || !pd.isShowing()) {
                pd = new ProgressDialog(SkatActivity.this, ProgressDialog.THEME_DEVICE_DEFAULT_LIGHT);
                pd.setTitle("ebb.dk");
                pd.setMessage("Vent venligst...");
                pd.setCancelable(false);
                pd.setIndeterminate(true);
                pd.show();
            }

            count++;
        }

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

    });
    wv.loadUrl("https://motorregister.skat.dk/dmr-front/appmanager/skat/dmr?_nfpb=true&_nfpb=true&_pageLabel=vis_koeretoej_side&_nfls=false");
}

0 个答案:

没有答案