android 中ProgressDialog实现全屏效果

做项目的时候,直接用到了一个ProgressDialog,需要实现全屏的效果,如下图所示,功能跑起来的时候发现不是全屏,只是包裹了当前的内容,如下图所示,不过查找一些资料,把问题解决了。

本文的知识点:

1、实现ProgressDialog的全屏效果
2、接口回调推荐的方式

项目要求实现的效果.png
刚开始实现的效果.png

代码实现:

1、布局



    

    

    


    
2、核心代码
 Window window = getWindow();
        WindowManager.LayoutParams layoutParams = window.getAttributes();
        layoutParams.width = WindowManager.LayoutParams.MATCH_PARENT;
        layoutParams.height = WindowManager.LayoutParams.MATCH_PARENT;
        layoutParams.gravity = gravity;
        window.setAttributes(layoutParams);
3、接口回调的实现方式
    public OnClickCancelListener mOnClickCancelListener;

    public void setOnClickCancelListener(OnClickCancelListener onClickCancelListener){
        this.mOnClickCancelListener = onClickCancelListener;
    }

    public interface OnClickCancelListener{
        void singleClick();
    }
4、接口回调的调用方式
mLoadingProgressDialog.setOnClickCancelListener(new LoadingProgressDialog.OnClickCancelListener() {

           @Override
           public void singleClick() {
               LogUtil.d(TAG,"点击取消查询===========");
               isContinueQuery =  true;
               dismissPayResultLoadingDialog();
           }
       });
5、全部代码实现
public class LoadingProgressDialog extends ProgressDialog {

    private static final String TAG = LoadingProgressDialog.class.getSimpleName();

    public LoadingProgressDialog(Context context) {
        super(context,R.style.style_custon_dialog);
        setCancelable(false);
        setCanceledOnTouchOutside(false);
    }


    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.custom_dialog_all_loading);
        Window window = getWindow();
        WindowManager.LayoutParams layoutParams = window.getAttributes();
        layoutParams.width = WindowManager.LayoutParams.MATCH_PARENT;
        layoutParams.height = WindowManager.LayoutParams.MATCH_PARENT;
        layoutParams.gravity = gravity;
        window.setAttributes(layoutParams);
        Button benCancel = (Button) findViewById(R.id.btn_cancel);
        benCancel.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                LogUtil.d(TAG,"benCancel================");
                mOnClickCancelListener.singleClick();
            }
        });
    }

    public OnClickCancelListener mOnClickCancelListener;

    public void setOnClickCancelListener(OnClickCancelListener onClickCancelListener){
        this.mOnClickCancelListener = onClickCancelListener;
    }

    public interface OnClickCancelListener{
        void singleClick();
    }
}

你可能感兴趣的:(android 中ProgressDialog实现全屏效果)