/** * 设置对话框模式是否可以点击外部取消 */ public void setDialogOutSideCancelable() { if (mDialog != null) { mDialog.setCancelable(mPickerOptions.cancelable); } }
public BottomSheetDialog cancelable(boolean cancelable){ super.setCancelable(cancelable); mCancelable = cancelable; return this; }
/** * Sets whether this dialog is cancelable with the * {@link android.view.KeyEvent#KEYCODE_BACK BACK} key. * @return The Dialog for chaining methods. */ public Dialog cancelable(boolean cancelable){ super.setCancelable(cancelable); mCancelable = cancelable; return this; }
public void setCancelable(boolean flag) { dialog.setCancelable(flag); }
public static Dialog showDialogForLoading(Activity context) { View view = LayoutInflater.from(context).inflate(R.layout.dialog_loading, null); TextView loadingText = (TextView)view.findViewById(R.id.id_tv_loading_dialog_text); loadingText.setText("加载中..."); mLoadingDialog = new Dialog(context, R.style.CustomProgressDialog); mLoadingDialog.setCancelable(true); mLoadingDialog.setCanceledOnTouchOutside(false); mLoadingDialog.setContentView(view, new LinearLayout.LayoutParams(LinearLayout.LayoutParams.MATCH_PARENT, LinearLayout.LayoutParams.MATCH_PARENT)); mLoadingDialog.show(); return mLoadingDialog; }
/** * 显示加载对话框 * @param context 上下文 * @param msg 对话框显示内容 * @param cancelable 对话框是否可以取消 */ public static Dialog showDialogForLoading(Activity context, String msg, boolean cancelable) { View view = LayoutInflater.from(context).inflate(R.layout.dialog_loading, null); TextView loadingText = (TextView)view.findViewById(R.id.id_tv_loading_dialog_text); loadingText.setText(msg); mLoadingDialog = new Dialog(context, R.style.CustomProgressDialog); mLoadingDialog.setCancelable(cancelable); mLoadingDialog.setCanceledOnTouchOutside(false); mLoadingDialog.setContentView(view, new LinearLayout.LayoutParams(LinearLayout.LayoutParams.MATCH_PARENT, LinearLayout.LayoutParams.MATCH_PARENT)); mLoadingDialog.show(); return mLoadingDialog; }
public void createDialog() { if (dialogView != null) { mDialog = new Dialog(context, R.style.custom_dialog2); mDialog.setCancelable(mPickerOptions.cancelable);//不能点外面取消,也不能点back取消 mDialog.setContentView(dialogView); Window dialogWindow = mDialog.getWindow(); if (dialogWindow != null) { dialogWindow.setWindowAnimations(R.style.picker_view_scale_anim); dialogWindow.setGravity(Gravity.CENTER);//可以改成Bottom } mDialog.setOnDismissListener(new DialogInterface.OnDismissListener() { @Override public void onDismiss(DialogInterface dialog) { if (onDismissListener != null) { onDismissListener.onDismiss(BasePickerView.this); } } }); } }
@NonNull @Override public Dialog onCreateDialog(Bundle savedInstanceState) { Dialog dialog = super.onCreateDialog(savedInstanceState); dialog.getWindow().requestFeature(Window.FEATURE_NO_TITLE); dialog.getWindow().setBackgroundDrawable(new ColorDrawable(Color.TRANSPARENT)); // タッチしても消えないように設定 dialog.setCancelable(false); // ビュー全体のリスナ dialog.setCanceledOnTouchOutside(false); dialog.setOnKeyListener(new DialogInterface.OnKeyListener() { @Override public boolean onKey(DialogInterface dialog, int keyCode, KeyEvent event) { // Disable Back key and Search key switch (keyCode) { case KeyEvent.KEYCODE_BACK: case KeyEvent.KEYCODE_SEARCH: return true; default: return false; } } }); return dialog; } }
splashDialog.setCancelable(false); splashDialog.show();
splashDialog.setCancelable(false); splashDialog.show();
splashDialog.setCancelable(false); splashDialog.show();
private void initDialog() { contentLayout = new FrameLayout(activity); contentLayout.setLayoutParams(new ViewGroup.LayoutParams(WRAP_CONTENT, WRAP_CONTENT)); contentLayout.setFocusable(true); contentLayout.setFocusableInTouchMode(true); dialog = new Dialog(activity); dialog.setCanceledOnTouchOutside(true);//触摸屏幕取消窗体 dialog.setCancelable(true);//按返回键取消窗体 dialog.setOnKeyListener(this); dialog.setOnDismissListener(this); Window window = dialog.getWindow(); if (window != null) { window.setGravity(Gravity.BOTTOM); window.setBackgroundDrawable(new ColorDrawable(Color.TRANSPARENT)); //AndroidRuntimeException: requestFeature() must be called before adding content window.requestFeature(Window.FEATURE_NO_TITLE); window.setContentView(contentLayout); } setSize(screenWidthPixels, WRAP_CONTENT); }
@Test public void shouldSetCancelable() { Dialog dialog = new Dialog(context); ShadowDialog shadow = shadowOf(dialog); dialog.setCancelable(false); assertThat(shadow.isCancelable()).isFalse(); }
public static Dialog show(Context ctx, String text) { final Dialog dialog = new Dialog(ctx, R.style.full_screen_dialog); dialog.setContentView(R.layout.progress_dialog); ((TextView) dialog.findViewById(R.id.label_loading)).setText(text); dialog.setCancelable(false); dialog.show(); return dialog; } }
final Dialog dialog=new Dialog(dialogactivity.this); dialog.setCancelable(false); dialog.setCanceledOnTouchOutside(false);
@Override public final void setCancelable(final boolean cancelable) { super.setCancelable(cancelable); this.cancelable = cancelable; }
public static Dialog showLoading(Activity context, String msg, boolean cancelable){ View view = LayoutInflater.from(context).inflate(R.layout.dialog_loading, null); TextView loadingText = (TextView) view.findViewById(R.id.id_tv_loading_dialog_text); loadingText.setText(msg); mLoadingDialog = new Dialog(context, R.style.CustomProgressDialog); mLoadingDialog.setCancelable(cancelable); mLoadingDialog.setCanceledOnTouchOutside(false); mLoadingDialog.setContentView(view, new LinearLayout.LayoutParams(LinearLayout.LayoutParams.MATCH_PARENT, LinearLayout.LayoutParams.MATCH_PARENT)); mLoadingDialog.show(); return mLoadingDialog; }
While creating your alert try Dialog alertDialog = new Dialog(currentActivity); alertDialog.getWindow().setFlags(WindowManager.LayoutParams.FLAG_FORCE_NOT_FULLSCREEN, WindowManager.LayoutParams.FLAG_WATCH_OUTSIDE_TOUCH); alertDialog.setCanceledOnTouchOutside(true); alertDialog.setCancelable(true); WindowManager.LayoutParams WMLP = alertDialog.getWindow().getAttributes(); WMLP.x = 0; WMLP.y = 0; WMLP.dimAmount = 0.0f; alertDialog .getWindow().setAttributes(WMLP);
@Override public void onCreate(@Nullable Bundle savedInstanceState) { super.onCreate(savedInstanceState); dialog = HTApp.getInstance().createLoadingDialog(getBaseActivity(),getString(R.string.now_refresh_msg)); dialog.setCancelable(true); dialog.setCanceledOnTouchOutside(true); }
public static BuildBean setCancelable(BuildBean bean) { if (bean.alertDialog != null) { bean.alertDialog.setCancelable(bean.cancelable); bean.alertDialog.setCanceledOnTouchOutside(bean.outsideTouchable); } else if (bean.dialog != null) { bean.dialog.setCancelable(bean.cancelable); bean.dialog.setCanceledOnTouchOutside(bean.outsideTouchable); } return bean; }