自定义Dialog实现透明无遮罩进度框

效果图:

 

自定义Dialog实现透明无遮罩进度框_第1张图片

  • 自定义Dialog继承自Dialog
public class ProgressDialog extends Dialog {

    ImageView ivloading;
    
    public ProgressDialog(Context context) {
        this(context,R.style.Theme_dialog);
    }
    
    public ProgressDialog(Context context, int style) {
        super(context, style);

        //set content
        View view = getLayoutInflater().inflate(R.layout.dlg_progress,null);
        setContentView(view);
        ivloading = view.findViewById(R.id.ivloading);
        ((AnimationDrawable)ivloading.getDrawable()).start();
        
        //set window params
        Window window = getWindow();
        WindowManager.LayoutParams params = window.getAttributes();
        params.gravity = Gravity.CENTER;
        params.dimAmount = 0;
        window.setAttributes(params);
    } 
}
params.dimAmount=0:设置dialog弹出后,背景不出现遮罩,默认会有遮罩

  • 布局文件:



    


  • Theme_dialog样式:
   

android:windowBackground设置dialog背景为透明

  • 使用:
ProgressDialog progressDialog;
.....
progressDialog = new ProgressDialog(this);
......
progressDialog.show();

你可能感兴趣的:(安卓控件,安卓UI,安卓基础)