Android webview 在右侧显示白条
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/2279978/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
webview showing white bar on right side
提问by Kshitij Aggarwal
I am giving the following method call to my webview client embedded in my layoutwv.loadData("<html><body bgcolor=\"Black\"></body></html>","text/html", "utf-8");
我正在对嵌入在我的布局中的 webview 客户端进行以下方法调用wv.loadData("<html><body bgcolor=\"Black\"></body></html>","text/html", "utf-8");
when i run this on the device, it shows a white vertical bar on the right side. I fixed the white thing by using webview.setBackgroundColor(Color.BLACK);
but i want to remove it completely
当我在设备上运行它时,它会在右侧显示一个白色的垂直条。我通过使用修复了白色的东西,webview.setBackgroundColor(Color.BLACK);
但我想完全删除它
Following is my layout xml
以下是我的布局xml
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
>
<TextView
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:text="@string/hello"
/>
<WebView android:id="@+id/wv1"
android:layout_height="fill_parent"
android:layout_width="fill_parent"
/>
</LinearLayout>
Any suggestions??
有什么建议??
回答by Chris Danielson
Use the following to hide but not remove the functionality of the scrollbar. The layout margin adjustment is a nasty work-around.
使用以下内容隐藏但不删除滚动条的功能。布局边距调整是一个令人讨厌的解决方法。
//webview being your WebView object reference.
webview.setScrollBarStyle(WebView.SCROLLBARS_OUTSIDE_OVERLAY);
//webview being your WebView object reference.
webview.setScrollBarStyle(WebView.SCROLLBARS_OUTSIDE_OVERLAY);
回答by Jonah
I would set margin: 0 and padding: 0 inside the . You could do something like
我会设置 margin: 0 和 padding: 0 在 . 你可以做类似的事情
<body style="margin: 0; padding: 0">
回答by Aaron T Harris
This may not be the "best" answer but it worked for me.
这可能不是“最佳”答案,但对我有用。
<WebView android:layout_marginRight="-7dip" />
Let me know if there is something better because this feels hackish to me.
让我知道是否有更好的东西,因为这对我来说感觉很黑。
回答by Martin
My app has a selectable night-mode which switches to white on black. The central View is a WebView displaying text.
我的应用程序有一个可选择的夜间模式,可以切换到黑底白字。中央视图是一个显示文本的 WebView。
For night-mode I used an extra css file that showed white text on a black backbround but users complained about the white scrollbar on the right. So I had much the same problem as outlined above. However, I needed to switch in and out of night-mode programatically at runtime but I didn't want merely to hide the scrollbars.
对于夜间模式,我使用了一个额外的 css 文件,该文件在黑色背景上显示白色文本,但用户抱怨右侧的白色滚动条。所以我遇到了与上述相同的问题。但是,我需要在运行时以编程方式切换夜间模式,但我不想仅仅隐藏滚动条。
The simple solution I used was:
我使用的简单解决方案是:
if (isNightMode()) {
webView.setBackgroundColor(Color.BLACK);
} else {
webView.setBackgroundColor(Color.WHITE);
}
Setting the backgroundColor of the WebView affected the scrollbars as required.
根据需要设置 WebView 的 backgroundColor 会影响滚动条。