Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
Android Studio Prevent Dialog From Closing
public class MyDialogFragment extends DialogFragment {
@NonNull
@Override
public Dialog onCreateDialog(@Nullable Bundle savedInstanceState) {
// ダイアログの作成
AlertDialog.Builder builder = new AlertDialog.Builder(getActivity());
builder.setTitle("タイトル")
.setMessage("ここにメッセージを入力します。")
.setPositiveButton("OK", new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int id) {
// このボタンを押した時の処理を書きます。
}
});
AlertDialog alertDialog = builder.create();
setCancelable(false);
alertDialog.setCanceledOnTouchOutside(false);
return alertDialog;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment