Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/android/205.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Android 在右侧显示白色条的webview_Android - Fatal编程技术网

Android 在右侧显示白色条的webview

Android 在右侧显示白色条的webview,android,Android,我正在对嵌入到布局中的webview客户端进行以下方法调用 wv.loadData(“,“text/html”,“utf-8”) 当我在设备上运行时,它在右侧显示一个白色竖条。我用webview.setBackgroundColor(Color.BLACK)修复了白色的东西但我想完全删除它 下面是我的布局xml <?xml version="1.0" encoding="utf-8"?> <LinearLayout xmlns:android="http://schemas.a

我正在对嵌入到布局中的webview客户端进行以下方法调用
wv.loadData(“,“text/html”,“utf-8”)

当我在设备上运行时,它在右侧显示一个白色竖条。我用
webview.setBackgroundColor(Color.BLACK)修复了白色的东西但我想完全删除它

下面是我的布局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>

有什么建议吗?

这可能不是“最佳”答案,但对我来说很有效

<WebView android:layout_marginRight="-7dip" />


让我知道是否有更好的方法,因为这让我感觉很不舒服。

我会在页面中设置边距:0和填充:0。你可以这样做

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

使用以下命令隐藏但不删除滚动条的功能。版面边距调整是一项棘手的工作


//webview是您的webview对象引用。
webview.setScrollBarStyle(webview.SCROLLBARS\u外部\u覆盖);

我的应用程序有一个可选择的夜间模式,可切换为黑白模式。中心视图是显示文本的网络视图

对于夜间模式,我使用了一个额外的css文件,在黑色背景上显示白色文本,但用户抱怨右侧的白色滚动条。因此,我遇到了与上述问题大致相同的问题。然而,我需要在运行时以编程方式切换夜间模式,但我不想仅仅隐藏滚动条

我使用的简单解决方案是:

if (isNightMode()) {
    webView.setBackgroundColor(Color.BLACK);
} else {
    webView.setBackgroundColor(Color.WHITE);
}

设置WebView的背景色会根据需要影响滚动条。

您可以向我们展示您正在使用的布局的xml吗?这是一个旁注。我不知道为什么,但是在XML文件中而不是在Java代码中设置它对我不起作用。@rushinge完全同意使用XML设置时这不起作用。这是一个记录在案的Android缺陷,您通常更喜欢WebView.SCROLLBARS\u内部的覆盖。这样,当您滚动视图时,滚动条就会显示出来。这是较新平台的默认行为,但在旧平台上不是(至少没有达到API级别11)。我是对的,这是黑客行为。请看上面Chris Danielson的解决方案。我实际上使用了类似的方法,但在不同的设备上出现了意想不到的行为。不要用这个。