Webview shows a white bar on the right side

I provide 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, a vertical vertical panel is displayed on the right side. I fixed a white thing using webview.setBackgroundColor(Color.BLACK); but I want to completely remove it.

Below is my xml layout

 <?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

+55
android
Feb 17 '10 at 10:49
source share
4 answers

Use the following to hide but not remove the scrollbar functionality. Adjusting the layout margin is an unpleasant job.

//webview being your WebView object reference. webview.setScrollBarStyle(WebView.SCROLLBARS_OUTSIDE_OVERLAY);

+147
May 04 '10 at 2:56 p.m.
source share

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

 <body style="margin: 0; padding: 0"> 
+9
Apr 25 2018-10-21T00:
source share

This may not be the best answer, but it worked for me.

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

Let me know if something is better, because it seems like a hacker to me.

+4
Apr 08 '10 at 19:54
source share

My app has a custom night mode that switches to white on black. The central view is a WebView displaying text.

In night mode, I used an extra css file that showed white text on black backbround, but users complained about the white scroll bar on the right. Therefore, I had the same problem as described above. However, I needed to turn the night mode on and off at runtime, but I didn't want to just hide the scroll bars.

A simple solution I used:

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

The backgroundColor WebView setting affected the scroll bars as needed.

+1
Oct 22 '11 at 12:21
source share



All Articles