从progressdialog中删除白色背景

时间:2016-02-05 11:40:40

标签: android

面对问题的好日子,我无法删除ProgressDialog后面的白色背景。我正在尝试将background=#00FFFFFF用于RelativeLayout,但没有结果。如何删除此背景或使其透明?

enter image description here

我的ProgressDialog代码:

public class Loading {
    private Context context;

    private ProgressDialog dialog;

    public Loading(Context context) {
        this.context = context;
    }

    public void show() {
        getDialog().show();
        getDialog().setContentView(R.layout.dialog_spinner);

    }

    public void dismiss() {
        if (dialog != null) {
            dialog.dismiss();
        }
    }

    public void error() {
        dismiss();
    }

    public void success() {
        dismiss();
    }

    public void error(RetrofitError error) {
        EventBus.getDefault().post(error);
    }

    public ProgressDialog getDialog() {
        if (dialog == null) {
            dialog = new ProgressDialog(context);
            dialog.setCancelable(true);
            dialog.setCanceledOnTouchOutside(false);

        }
        return dialog;
    }
}

dialog_spinner布局:

<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:background="@drawable/dialog_progress_background">

    <LinearLayout
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_centerHorizontal="true"
        android:layout_centerVertical="true"
        android:orientation="horizontal">

        <ProgressBar
            android:id="@+id/progressBar"
            style="?android:attr/progressBarStyle"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content" />

        <TextView
            android:id="@+id/textView1"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_marginTop="20dp"
            android:text="Loading..."
            android:textColor="#FFFFFF" />
    </LinearLayout>
</RelativeLayout>

和dialog_progress_background形状:

<?xml version="1.0" encoding="utf-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android">
    <corners android:radius="10dp" />

    <solid android:color="#80000000" />


</shape>

1 个答案:

答案 0 :(得分:3)

添加以下代码

dialog.getWindow().setBackgroundDrawableResource(android.R.color.transparent);     
getDialog().setContentView(R.layout.dialog_spinner);

我希望它适合你。