我按照以下链接定制进度对话框:
I have followed following links to customize the progress dialog :
How轻松中心进度指示器ProgressDialog(没有标题/文本传承下去)
定制进度对话框中的android?
我要创建自定义进度就像这个图像对话框但是code不显示在我的application.Please进度对话框指导我如何做到这一点?同时指导我根据我的项目主题,我怎样才能改变进度对话框的颜色?
I want to create custom progress dialog like in this image but that code does not show a progress dialog in my application.Please guide me how to do this ? Also guide me how can i change the color of progress dialog according to my projects theme ?
我已经做了这种方式:
使用这个类自定义进度对话框
public class CustomProgressbar extends Dialog {
private static CustomProgressbar mCustomProgressbar;
private CustomProgressbar mProgressbar;
private OnDismissListener mOnDissmissListener;
private CustomProgressbar(Context context) {
super(context);
requestWindowFeature(Window.FEATURE_NO_TITLE);
setContentView(R.layout.dialog_progressbar);
this.getWindow().setBackgroundDrawableResource(android.R.color.transparent);
}
public CustomProgressbar(Context context, Boolean instance) {
super(context);
mProgressbar = new CustomProgressbar(context);
}
@Override
public void onBackPressed() {
super.onBackPressed();
if (mOnDissmissListener != null) {
mOnDissmissListener.onDismiss(this);
}
}
public static void showProgressBar(Context context, boolean cancelable) {
showProgressBar(context, cancelable, null);
}
public static void showProgressBar(Context context, boolean cancelable, String message) {
if (mCustomProgressbar != null && mCustomProgressbar.isShowing()) {
mCustomProgressbar.cancel();
}
mCustomProgressbar = new CustomProgressbar(context);
mCustomProgressbar.setCancelable(cancelable);
mCustomProgressbar.show();
}
public static void showProgressBar(Context context, OnDismissListener listener) {
if (mCustomProgressbar != null && mCustomProgressbar.isShowing()) {
mCustomProgressbar.cancel();
}
mCustomProgressbar = new CustomProgressbar(context);
mCustomProgressbar.setListener(listener);
mCustomProgressbar.setCancelable(Boolean.TRUE);
mCustomProgressbar.show();
}
public static void hideProgressBar() {
if (mCustomProgressbar != null) {
mCustomProgressbar.dismiss();
}
}
private void setListener(OnDismissListener listener) {
mOnDissmissListener = listener;
}
public static void showListViewBottomProgressBar(View view) {
if (mCustomProgressbar != null) {
mCustomProgressbar.dismiss();
}
view.setVisibility(View.VISIBLE);
}
public static void hideListViewBottomProgressBar(View view) {
if (mCustomProgressbar != null) {
mCustomProgressbar.dismiss();
}
view.setVisibility(View.GONE);
}
public void showProgress(Context context, boolean cancelable, String message) {
if (mProgressbar != null && mProgressbar.isShowing()) {
mProgressbar.cancel();
}
mProgressbar.setCancelable(cancelable);
mProgressbar.show();
}
}
dialog_progressbar.xml
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:background="@drawable/bg_progressbar"
android:gravity="center"
android:padding="10dp" >
<ProgressBar
android:id="@+id/progressbar"
android:layout_width="wrap_content"
android:layout_height="wrap_content" />
</LinearLayout>
添加绘制文件命名为 bg_progressbar.xml 在绘制文件夹:
Add drawable file named with bg_progressbar.xml in drawable folder:
<?xml version="1.0" encoding="utf-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android"
android:shape="rectangle" >
<solid android:color="#7F000000" />
<corners
android:bottomLeftRadius="5dp"
android:bottomRightRadius="5dp"
android:topLeftRadius="5dp"
android:topRightRadius="5dp" />
</shape>
现在,每当你想为开始进展对话框,只写 1 行code:
Now whenever you want to start Progress Dialog, just write 1 line code:
CustomProgressbar.showProgressBar(MainActivity.this, false);
每当你想为驳回进展对话框,只写 1 行 code:
Whenever you want to dismiss Progress Dialog, just write 1 line code:
CustomProgressbar.hideProgressBar();
希望这会帮助你。
Hope this will help you.