创建一个透明的加载动画Dialog

定义style


创建Dialog

Dialog  protocolDialog = new Dialog(context, R.style.LoadProgress);
        LayoutInflater inflater = (LayoutInflater) context
                .getSystemService(Context.LAYOUT_INFLATER_SERVICE);
        LinearLayout layout = (LinearLayout) inflater.inflate(
                R.layout.dialog_loadprogress, null);
        protocolDialog.setCanceledOnTouchOutside(false);

        protocolDialog.setContentView(layout);
        protocolDialog.setOnKeyListener(new DialogInterface.OnKeyListener() {
            @Override
            public boolean onKey(DialogInterface dialog, int keyCode, KeyEvent event) {
                if (keyCode == KeyEvent.KEYCODE_SEARCH) {
                    return true;
                } else {
                    return true; //默认返回 false,这里false不能屏蔽返回键,改成true就可以了
                }
            }

        });

布局文件dialog_loadprogress,



        


调用

 public void show() {
        if (protocolDialog != null && !protocolDialog.isShowing() && context != null && !context.isFinishing()) {
            protocolDialog.show();
        }
    }

    public void close() {
        if (protocolDialog != null) {
            if (protocolDialog.isShowing()) {
                protocolDialog.dismiss();
            }
        }

你可能感兴趣的:(创建一个透明的加载动画Dialog)