如何在WebView Android应用程序中保持响应式布局?

时间:2015-09-08 11:54:22

标签: android webview

我使用WebView创建了一个Android应用。此应用程序显示网站的内容。有许多内部链接和外部链接(具有301重定向)。内部链接是正确的,但是当我点击外部链接时,我看到全屏桌面布局而不是页面的响应版本,它看起来非常糟糕。

如何编辑以下代码以便始终获得适合屏幕的响应式布局?

 webView.setWebViewClient(new WebViewClient() {
        @Override
        public void onPageFinished(final WebView view, String url) {
            // hide loading image
            Handler mHandler = new Handler();
            mHandler.postDelayed(new Runnable() {
                @Override
                public void run() {
                    progressBar.setVisibility(View.GONE);
                }
            }, 1000);
        }
        @Override
        public void onReceivedError(WebView view, int errorCode,String description, String failingUrl) {
            AlertDialog.Builder builder = new AlertDialog.Builder(MainActivity.this);
            builder.setMessage(description).setPositiveButton(getText(R.string.ok), null).setTitle("onReceivedError");
            builder.show();
        }

    });

    // load url (if connection available
    if (isInternetConnected(this)) {
        String URL = "http://www.example.com/";
        webView.loadUrl(URL);
    }else{
       // showAlertDialog(this, "No Internet Connection",
      //          "You don't have internet connection.", false);
        new AlertDialog.Builder(this)
                .setTitle("No Internet Connection")
                .setMessage("You don't have internet connection.")
                .setCancelable(false)
                .setPositiveButton("Retry", new DialogInterface.OnClickListener() {
                    @Override
                    public void onClick(DialogInterface dialog, int which) {
                        // whatever...
                        finish(); //Close current activity
                        startActivity(getIntent()); //Restart it

                    }
                }).create().show();
    }

0 个答案:

没有答案