0

我有此代码以显示进度对话框:

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

这是我的主要活动布局:

<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 中的按钮时,会出现进度对话框,但页面的背景颜色变为gray

在此处输入图像描述 --------> 在此处输入图像描述

我希望它默认为白色,进度对话框文本为黑色。我错过了什么?

4

4 回答 4

1

我通过添加<include layout="@layout/progress_bar" />主 Activity 布局解决了我的问题。

然后我在 progressDialog 布局中为 Progress Dialog 命名,例如android:id="@+id/progress_bar.

然后使用这段代码,我隐藏了对话框:

@Override
protected void onPostExecute(String result) {
    ProgressBar progressBar = (ProgressBar) findViewById(R.id.progress_bar);
    progressBar.setVisibility(View.GONE);
}
于 2013-04-05T12:47:11.277 回答
0

您可以使用可绘制文件执行此操作

第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>
于 2013-04-03T11:53:58.667 回答
0
    <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 是颜色代码...在此处使用灰色颜色代码...

于 2013-04-03T12:45:03.730 回答
0

尝试在您的 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>
于 2013-04-03T12:59:36.053 回答