webview showing white bar on right side

Android

Android Problem Overview


I am giving the following method call to my webview client embedded in my layout
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

Following is my layout 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??

Android Solutions


Solution 1 - Android

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);

Solution 2 - Android

I would set margin: 0 and padding: 0 inside the . You could do something like

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

Solution 3 - Android

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.

Solution 4 - Android

My app has a selectable night-mode which switches to white on black. The central View is a WebView displaying text.

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.

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.

Attributions

All content for this solution is sourced from the original question on Stackoverflow.

The content on this page is licensed under the Attribution-ShareAlike 4.0 International (CC BY-SA 4.0) license.

Content TypeOriginal AuthorOriginal Content on Stackoverflow
QuestionKshitij AggarwalView Question on Stackoverflow
Solution 1 - AndroidChris DanielsonView Answer on Stackoverflow
Solution 2 - AndroidJonahView Answer on Stackoverflow
Solution 3 - AndroidAaron T HarrisView Answer on Stackoverflow
Solution 4 - AndroidMartinView Answer on Stackoverflow