在自定义进度条中,白色背景显示在 Android。如何删除它?
In the custom progress bar, white background is showing in Android. How to remove that?
我正在使用一个基本上会旋转的小 image/icon 制作自定义进度条。但在背景中有白色补丁或背景正在显示。我把图片附在这里..
我为此使用了以下代码:
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%" />
我怎样才能去掉这里的白色背景..请帮忙。
这对我有用。将其添加到对话框的 onCreate 中。
getWindow().setBackgroundDrawable(new ColorDrawable(android.graphics.Color.TRANSPARENT));
最简单的方法,将这一行添加到你的进度条中XML:
android:background="@android:color/transparent"
只需执行以下方法即可完成
在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");
我正在使用一个基本上会旋转的小 image/icon 制作自定义进度条。但在背景中有白色补丁或背景正在显示。我把图片附在这里..
我为此使用了以下代码:
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%" />
我怎样才能去掉这里的白色背景..请帮忙。
这对我有用。将其添加到对话框的 onCreate 中。
getWindow().setBackgroundDrawable(new ColorDrawable(android.graphics.Color.TRANSPARENT));
最简单的方法,将这一行添加到你的进度条中XML:
android:background="@android:color/transparent"
只需执行以下方法即可完成
在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");