如何使用javascript

时间:2015-12-16 09:30:29

标签: javascript android html android-webview

我在我的应用程序中使用了android webview。我注意到它有内置边缘。所以需要根据UI要求删除它。

我已经用它来获得完美的结果。

 @Override
        public void onPageFinished(WebView view, String url) {
//            super.onPageFinished(view, url);
            webView.getSettings().setJavaScriptEnabled(true);
            webView.loadUrl("javascript:document.body.style.margin=\"0%\"; void 0");
            webView.setVisibility(View.VISIBLE);
        }
当它被通知时,它会被刷新,看起来太糟糕了。  但是我们可以将JavaScript应用到我们的HTML代码中吗?  我在那边使用<script> <script/>但没有结果。

webView.loadDataWithBaseURL(null, "<style>a{color:#3D7B8A; text-decoration:none}</style>"+ getDescription().replace("<p>", "<p style= \"line-height: 150%; text-align: justify;\" >"), "text/html", "utf-8",
                    null);

请告知。

1 个答案:

答案 0 :(得分:3)

据我所知,从上面的代码中你还没有padding = 0

我在谷歌上看到并发现了这个问题和答案,你可能想看看:Remove unwanted White Space in WebView Android

  

默认情况下, webview 在正文中有一些边距/填充。如果要删除该填充/边距,则覆盖正文标记并添加边距,如:

     

<body style="margin: 0; padding: 0">