在自定义进度栏中,白色背景显示在Android中。如何删除?

时间:2015-05-09 15:28:10

标签: android progress-bar progressdialog

我正在使用一个基本上会旋转的小图像/图标来制作自定义进度条。但在背景中有白色补丁或背景显示。我已将图像附在此处..

我使用了以下代码:

CustomDialog.java

 public class CustomDialog extends Dialog{

    public Activity c;
     public CustomDialog(Activity a) {
            super(a);
            // TODO Auto-generated constructor stub
            this.c = a;
          }

     public CustomDialog(Activity a, int s) {
            super(a, s);
            // TODO Auto-generated constructor stub
            this.c = a;
          }

     @Override
      protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        requestWindowFeature(Window.FEATURE_NO_TITLE);
        getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN,
                WindowManager.LayoutParams.FLAG_FULLSCREEN);
        setContentView(R.layout.progressbar);
        setCancelable(true);
      }

}

progressbar.xml

<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent"
    android:background="@android:color/transparent"
    android:gravity="center"
    android:orientation="vertical" >

    <ProgressBar
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_centerInParent="true"
        android:indeterminate="true"
        android:background="@android:color/transparent"
        android:indeterminateDrawable="@drawable/my_progress_interminate" >
    </ProgressBar>

</RelativeLayout>

my_progress_interminate.xml

<?xml version="1.0" encoding="utf-8"?>
<animated-rotate xmlns:android="http://schemas.android.com/apk/res/android"
    android:drawable="@drawable/sai_icon" 
    android:pivotX="50%"
    android:pivotY="50%" />

我如何在这里删除白色背景..请帮忙。 image

3 个答案:

答案 0 :(得分:3)

这对我有用。将其添加到对话框的onCreate中。

getWindow().setBackgroundDrawable(new ColorDrawable(android.graphics.Color.TRANSPARENT));

答案 1 :(得分:1)

最简单的方法是,将此行添加到进度条XML:

android:background="@android:color/transparent"

答案 2 :(得分:1)

只需执行以下方法即可完成

在res-&gt; values-&gt;样式中添加以下代码

<style name="MyGravity" parent="android:Theme.Material.Dialog" ></style>

然后创建你的ProgressDialog,如下所述

ProgressDialog dialog = new ProgressDialog(ctx, R.style.MyGravity);
dialog.getWindow().setBackgroundDrawableResource(android.R.color.transparent);
dialog.setTitle("Your Title");
dialog.setMessage("Your Message");