【问题标题】:In the custom progress bar, white background is showing in Android. How to remove that?在自定义进度条中,Android 中显示白色背景。如何删除它?
【发布时间】:2015-05-09 15:28:09
【问题描述】:

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

我为此使用了以下代码:

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%" />

我怎样才能在这里删除白色背景.. 请帮忙。

【问题讨论】:

  • 在这个图标里面...所以改变这个图标 android:drawable="@drawable/sai_icon"

标签: android progress-bar progressdialog


【解决方案1】:

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

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

【讨论】:

    【解决方案2】:

    最简单的方法,将这一行添加到您的进度条 XML 中:

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

    【讨论】:

      【解决方案3】:

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

      在 res->values->styles 中添加以下代码

      <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");
      

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 2014-08-05
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2020-09-03
        • 2016-08-06
        • 1970-01-01
        相关资源
        最近更新 更多