Skip to content

Instantly share code, notes, and snippets.

Created January 29, 2021 11:28
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
Star You must be signed in to star a gist
What would you like to do?
Android Studio AlertDialog with ImageView 2
public class MyDialogFragment extends DialogFragment {
public Dialog onCreateDialog(@Nullable Bundle savedInstanceState) {
// カスタムレイアウトの用意
LayoutInflater inflater = requireActivity().getLayoutInflater();
View customAlertView = inflater.inflate(R.layout.custom_dialog, null);
// タイトルの変更
TextView title = customAlertView.findViewById(;
// メッセージの変更
TextView message = customAlertView.findViewById(;
// ダイアログの作成
AlertDialog.Builder builder = new AlertDialog.Builder(getActivity());
.setPositiveButton("OK", new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int id) {
// このボタンを押した時の処理を書きます。
return builder.create();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment