Rajath
Rajath

Reputation: 11946

WebView appears white while progressbar loads

I have a ProgressBar that is shown when a WebView is loading. I'd like the ProgressBar to be shown with a small size, while the background is black. Then I can dismiss the progress bar when the WebView has loaded.

The problem I have is that the WebView is white while it is loading. Is there any way to make it black? If I set the background color of the WebView to black, for a brief second, it is still white, and makes the loading quite ugly.

The layout of the Activity is:

<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools"
    android:layout_width="match_parent"
    android:layout_height="match_parent" >

    <WebView
        android:id="@+id/WebView"
        android:layout_width="fill_parent"
        android:layout_height="fill_parent" />

    <ProgressBar
        android:id="@+id/ProgressBar"
        style="?android:attr/progressBarStyle"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_centerInParent="true"
        android:visibility="gone" />

</RelativeLayout>

Alternatively, should I use some sort of an image that looks similar to the Android progress bar?

Upvotes: 1

Views: 1804

Answers (2)

Rogier van het Schip
Rogier van het Schip

Reputation: 937

Add the following to your XML:

<WebView
    android:id="@+id/webview"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:background="#ff000000" />

And do this in code:

public View onCreateView(LayoutInflater inflater, ViewGroup container, 
    Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);

    // Inflate the layout for this fragment
    View view = inflater.inflate(R.layout.feed_fragment, container, false);

    WebView webView = (WebView) view.findViewById(
            R.id.webview);
    webView.setBackgroundColor(0);

    return view;
}

Upvotes: 2

Saad
Saad

Reputation: 309

Add this in your relativeLayout

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent" 
android:background="#000000">

Upvotes: 0

Related Questions