Skip to content

Instantly share code, notes, and snippets.

@codeforfun-jp
Created December 21, 2023 13:51
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save codeforfun-jp/1f7404c0e5f5c1ab398039a37c1f65b5 to your computer and use it in GitHub Desktop.
Save codeforfun-jp/1f7404c0e5f5c1ab398039a37c1f65b5 to your computer and use it in GitHub Desktop.
Android Studio AlertDialog with ImageView
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