-
-
Save codeforfun-jp/1f7404c0e5f5c1ab398039a37c1f65b5 to your computer and use it in GitHub Desktop.
Android Studio AlertDialog with ImageView
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public class MyDialogFragment extends DialogFragment { | |
@NonNull | |
@Override | |
public Dialog onCreateDialog(@Nullable Bundle savedInstanceState) { | |
// カスタムレイアウトの用意 | |
LayoutInflater inflater = requireActivity().getLayoutInflater(); | |
View customDialogView = inflater.inflate(R.layout.custom_dialog, null); | |
// タイトル | |
TextView title = customDialogView.findViewById(R.id.title); | |
title.setText("こんにちは!"); | |
// 画像名 | |
TextView imageName = customDialogView.findViewById(R.id.image_name); | |
imageName.setText("アイコン画像"); | |
// メッセージ | |
TextView message = customDialogView.findViewById(R.id.message); | |
message.setText("ここにメッセージを入力します。ここにメッセージを入力します。ここにメッセージを入力します。"); | |
return new AlertDialog.Builder(requireActivity()) | |
.setView(customDialogView) | |
.setPositiveButton("OK", (dialog, id) -> { | |
}) | |
.create(); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment