WebView设置页面属性(padding等)

        mWebView.setWebViewClient(new WebViewClient() {
            @Override
            public boolean shouldOverrideUrlLoading(WebView view, WebResourceRequest request) {
                String url = request.getUrl().toString();
                if (!TextUtils.isEmpty(url) && (url.startsWith("http:") || url.startsWith("https:") || url.startsWith("file:"))) {
                    view.loadUrl(url);
                }
                return true;
            }

            @Override
            public void onPageFinished(WebView view, String url) {
                mViewModel.setCurrentState(PageState.LOAD_SUCCESS);
                if (!mPageConfig.isContentTop() && mPageConfig.isScrollMode()) {
                    mWebView.loadUrl("javascript:document.body.style.paddingTop=\"" + (VideoClipsUiHelper.pxToDip(mScrollYChangeBackground) + VideoClipsUiHelper.getStatusHeightDp()) + "px\"; void 0");
                    mWebView.loadUrl("javascript:document.body.style.background=\"#FFFFFF\"; void 0");
                }
            }

            @Override
            public void onReceivedError(WebView view, WebResourceRequest request, WebResourceError error) {
                mViewModel.setCurrentState(PageState.LOAD_ERROR);
            }
        });

        mWebView.loadUrl(mPageConfig.getUrl());

推荐阅读更多精彩内容