Ali
Ali

Reputation: 9994

Window background color for a Progress Dialog

I have this code in order to display progress dialog:

@Override
public void onPreExecute() {
    if(progress == null)
    progress = ProgressDialog.show(MainActivity2.this, null , null);
    progress.setContentView(R.layout.progressbar_activity);
}

This is my progressDialog layout.

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:id="@+id/layout_root"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:orientation="horizontal" >

    <ProgressBar
         android:layout_width="wrap_content"
         android:layout_height="wrap_content"
         style="@android:style/Widget.ProgressBar.Small.Inverse"
         android:layout_marginRight="5dp" />

     <TextView
         android:layout_width="wrap_content"
         android:layout_height="wrap_content"
         android:text="@string/loading" />

</LinearLayout>

And this is my main Activity layout:

<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="@android:color/white"
    android:orientation="vertical"
    tools:context=".MainActivity" >

    <LinearLayout
        android:id="@+id/tittle_bar"
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"
        android:background="@android:color/black"
        android:gravity="center"
        android:orientation="vertical"
        android:paddingTop="6dip" >

        <Button
            android:id="@+id/start_progress"
            android:layout_width="fill_parent"
            android:layout_height="fill_parent"
            android:text="@string/hello_world" />
    </LinearLayout>

</RelativeLayout>

As you see the background color is white.

When I click on the button in mainActivity the progress dialog appears, but the background color of the page becomes gray.

enter image description here --------> enter image description here

I want it to be white as default and the progress dialog text as black. what am I missing?

Upvotes: 0

Views: 3184

Answers (4)

Ali
Ali

Reputation: 9994

I solved my problem by adding <include layout="@layout/progress_bar" /> in main Activity layout.

Then I gave a name to Progress Dialog in progressDialog layout such as android:id="@+id/progress_bar.

And then with this code, I hided the dialog:

@Override
protected void onPostExecute(String result) {
    ProgressBar progressBar = (ProgressBar) findViewById(R.id.progress_bar);
    progressBar.setVisibility(View.GONE);
}

Upvotes: 1

sromku
sromku

Reputation: 4683

Try in your progressDialog layout to use transparent background for main LinearLayout and black color for the TextView.

Like this:

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:id="@+id/layout_root"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:orientation="horizontal" 
    android:background="#00000000">

    <ProgressBar
         android:layout_width="wrap_content"
         android:layout_height="wrap_content"
         style="@android:style/Widget.ProgressBar.Small.Inverse"
         android:layout_marginRight="5dp" />

    <TextView
         android:layout_width="wrap_content"
         android:layout_height="wrap_content"
         android:text="@string/loading"
         android:textColor="#000000" />
</LinearLayout>

Upvotes: 0

ashish.n
ashish.n

Reputation: 1224

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

<ProgressBar
    android:layout_width="40dip"
    android:layout_height="40dip"
    android:layout_centerHorizontal="true"
    android:layout_centerVertical="true"
    style="?android:attr/progressBarStyleInverse"
    android:progressBarStyle="@android:attr/progressBarStyleLarge"/>

 </RelativeLayout>



RelativeLayout layout = (RelativeLayout) inflater.inflate(
                R.layout.splash_progress, null);
        layout.setBackgroundColor("#336C10".hashCode());

336c10 is color code...use color code for gray here...

Upvotes: 0

Nirav Ranpara
Nirav Ranpara

Reputation: 13785

You can do this using drawable file

STEP - 1)

main.xml:(add this to your main.xml):

<ProgressBar 
android:id="@+id/ProgressBar01" 
android:layout_width="121dp" 
android:layout_height="15dp" 
android:progress="50"
android:max="100" 
android:secondaryProgress="0"
style="?android:attr/progressBarStyleHorizontal" 
android:progressDrawable="@drawable/myprogressbar" 
android:layout_marginTop="10dp"
/>

STEP - 2) myprogressbar.xml (save this xml in drawable folder)

<layer-list xmlns:android="http://schemas.android.com/apk/res/android">
    <item android:id="@android:id/background">
        <shape>
            <corners android:radius="25dip" />
            <gradient android:startColor="#C0C0C0" android:centerColor="#F8F8FF"
                android:centerY="0.75" android:endColor="#ffffff" android:angle="90" />
            <stroke android:width="1dp" android:color="#6B8E23" />
        </shape>
    </item>
    <item android:id="@android:id/progress">
        <clip>
            <shape>
                <corners android:radius="25dip" />
                <gradient android:startColor="#9ACD32" android:endColor="#FFFF00"
                    android:angle="90" />
                <stroke android:width="1dp" android:color="#6B8E23" />
            </shape>
        </clip>
    </item>
</layer-list>

Upvotes: 0

Related Questions