protected AlertDialog alertDialog=null;
public void lock(){
if(alertDialog==null){
AlertDialog.Builder builder = new AlertDialog.Builder(this);
builder.setCancelable(false);
alertDialog=builder.create();
alertDialog.show();
Window window = alertDialog.getWindow();//得到AlertDialog的Window
window.setContentView(R.layout.lock);//给Window设置自定义布局
}else {
alertDialog.show();
}
}
public void unLock(){
if(alertDialog != null){
alertDialog.dismiss();
}
}
布局文件
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:gravity="center"
android:orientation="vertical">
<ProgressBar
android:layout_width="wrap_content"
android:layout_height="wrap_content" />
</LinearLayout>
使用AlertDialog加载自定义布局完成,很好用而且不会占用很多资源