效果图:
Demo:files.cnblogs.com/files/liujingg/ProgressDialog.rar
半透明圆角背景 custom_progressbar.xml
<?xml version="1.0" encoding="utf-8"?> <shape xmlns:android="http://schemas.android.com/apk/res/android" > <solid android:color="#33000000" /> <corners android:radius="10dp" /> </shape>
自定义ProgressBar custom_progressdialog.xml
<?xml version="1.0" encoding="utf-8"?> <rotate xmlns:android="http://schemas.android.com/apk/res/android" android:fromDegrees="0" android:pivotX="50%" android:pivotY="50%" android:toDegrees="360" > <shape android:innerRadiusRatio="2.5" android:shape="ring" android:thicknessRatio="20" android:useLevel="false" > <gradient android:centerColor="#8B8B8B" android:endColor="#666666" android:startColor="#ffffff" android:type="sweep" /> </shape> </rotate>
自定义ProgressDialog的布局
<?xml version="1.0" encoding="utf-8"?> <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" android:id="@+id/dialog_view" android:layout_width="fill_parent" android:layout_height="fill_parent" android:background="@drawable/custom_progressdialog" android:gravity="center" android:orientation="vertical" android:paddingBottom="10dp" android:paddingLeft="20dp" android:paddingRight="20dp" android:paddingTop="16dp" > <ProgressBar android:layout_width="wrap_content" android:layout_height="wrap_content" android:indeterminateDrawable="@drawable/custom_progressbar" /> <TextView android:id="@+id/tipTextView" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_gravity="clip_horizontal" android:layout_marginTop="5dp" android:gravity="center_horizontal" android:textColor="#FFFFFF" /> </LinearLayout>
自定义style
<style name="loading_dialog" parent="android:style/Theme.Dialog"> <item name="android:windowFrame">@null</item> <item name="android:windowNoTitle">true</item> <item name="android:windowBackground">@drawable/custom_progressdialog</item> <item name="android:windowIsFloating">true</item> <item name="android:windowContentOverlay">@null</item> </style>
调用: createLoadingDialog(this, "加载中...").show();
public Dialog createLoadingDialog(Context context, String msg) { LayoutInflater inflater = LayoutInflater.from(context); View v = inflater.inflate(R.layout.progressdialog_no_deal, null); LinearLayout layout = (LinearLayout) v.findViewById(R.id.dialog_view); TextView tipTextView = (TextView) v.findViewById(R.id.tipTextView); tipTextView.setText(msg); Dialog loadingDialog = new Dialog(context, R.style.loading_dialog); loadingDialog.setCancelable(true); loadingDialog.setContentView(layout, new LinearLayout.LayoutParams( LinearLayout.LayoutParams.MATCH_PARENT, LinearLayout.LayoutParams.MATCH_PARENT)); return loadingDialog; }