Цвет фона окна для диалога прогресса

У меня есть этот код для отображения диалогового окна прогресса:

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

Это мой макет progressDialog.

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

И это мой основной макет Activity:

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

Как видите, цвет фона белый.

Когда я нажимаю кнопку в mainActivity, появляется диалоговое окно прогресса, но цвет фона страницы становится серым.

введите здесь описание изображения--------> введите здесь описание изображения

Я хочу, чтобы по умолчанию он был белым, а текст диалогового окна прогресса - черным. что мне не хватает?


person Ali    schedule 03.04.2013    source источник


Ответы (4)


Я решил свою проблему, добавив <include layout="@layout/progress_bar" /> в основной макет Activity.

Затем я дал имя Progress Dialog в макете progressDialog, например android:id="@+id/progress_bar.

И затем с помощью этого кода я скрыл диалог:

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

Вы можете сделать это, используя файл drawable

ШАГ 1)

main.xml: (добавьте это в свой 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"
/>

ШАГ - 2) myprogressbar.xml (сохраните этот xml в папке с возможностью рисования)

<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>
person Nirav Ranpara    schedule 03.04.2013
comment
Я добавил изображение, касающееся моей проблемы. Я думаю, что ваш код не то, что я имел в виду. - person Ali; 03.04.2013

    <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 - это цветовой код... используйте цветовой код для серого здесь...

person ashish.n    schedule 03.04.2013

Попробуйте в своем макете progressDialog использовать прозрачный фон для основного LinearLayout и черный цвет для TextView.

Как это:

<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>
person sromku    schedule 03.04.2013