【问题标题】:Android webview has white border around it and how can i get rid of it?Android webview周围有白色边框,我该如何摆脱它?
【发布时间】:2013-03-20 16:46:19
【问题描述】:

我有一个使用 webview 加载网页的 android 应用程序,但是在图形布局和应用程序中它显示白色粗边框,我尝试调整大小并尝试更改 XML 布局文件中的宽度和高度,但是不用找了。请查看下图以供参考。

【问题讨论】:

    标签: android web webview android-webview


    【解决方案1】:

    这似乎对我有用:

    String frameString = "<html><body style='margin:0;padding:0;'><iframe src=\"http://k-video.com/\" height=\"410\" width=\"320\" frameborder=\"0\" allowfullscreen></iframe></body></html>";
    

    希望对你有帮助!

    【讨论】:

      【解决方案2】:

      您可以看到的这个白色边框可能只是来自 webview 的布局容器的背景。请确保您在 web 视图的布局或边距上没有填充。

      【讨论】:

      • 谢谢,布局边距默认在res/values/dimens.xml 中定义。
      • dimens.xml 内边距设置为 16dp 应为 0dp:&lt;resources&gt; &lt;!-- Default screen margins, per the Android Design guidelines. --&gt; &lt;dimen name="activity_horizontal_margin"&gt;0dp&lt;/dimen&gt; &lt;dimen name="activity_vertical_margin"&gt;0dp&lt;/dimen&gt; &lt;/resources&gt;
      【解决方案3】:

      尝试像这样修改您的 HTML 内容:

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

      【讨论】:

        【解决方案4】:

        您可以使用webview.setBackgroundColor() 设置WebView 的背景颜色。

        我使用以下功能将WebView 背景设置为透明(不可见)和白色:

        private void setWebviewTransparency(final boolean transparent) {
            final int color = transparent ? 0 : Color.WHITE;
            webview.setBackgroundColor(color);
        }
        

        如果您的网页源未指定背景颜色,则此颜色仅在字段区域中有效。如果页面源确实指定了背景,那么这种颜色只会影响@Marcin 正确处理的填充区域。

        【讨论】:

          【解决方案5】:
          <html>
             <body style='margin:0;padding:0;'>
               <iframe width="100%" height="100%" src="https://www.youtube.com/embed/$mVideoId" frameborder="0" allow="accelerometer; autoplay; encrypted-media; gyroscope; picture-in-picture" allowfullscreen>
               </iframe>
             </body>
          </html>
          

          mVideoId 中替换为您的 youtube videoId

          上面的 iframe 字符串适用于我播放没有边距和填充的 youtube 视频。

          【讨论】:

            【解决方案6】:

            右键单击 WebView 并单击删除容器。就这么简单!

            【讨论】:

            • 这解决了我的问题。我很沮丧。谢谢你给了我那个微笑:)
            猜你喜欢
            • 1970-01-01
            • 1970-01-01
            • 1970-01-01
            • 1970-01-01
            • 1970-01-01
            • 2021-08-10
            • 1970-01-01
            • 1970-01-01
            • 1970-01-01
            相关资源
            最近更新 更多