Skip to content

Instantly share code, notes, and snippets.

@codeforfun-jp
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
Embed
What would you like to do?
Android Studio AlertDialog with ImageView 2
public class MyDialogFragment extends DialogFragment {
@NonNull
@Override
public Dialog onCreateDialog(@Nullable Bundle savedInstanceState) {
// カスタムレイアウトの用意
LayoutInflater inflater = requireActivity().getLayoutInflater();
View customAlertView = inflater.inflate(R.layout.custom_dialog, null);
// タイトルの変更
TextView title = customAlertView.findViewById(R.id.title);
title.setText("こんにちは!");
// メッセージの変更
TextView message = customAlertView.findViewById(R.id.message);
message.setText("ここにメッセージを入力します。ここにメッセージを入力します。ここにメッセージを入力します。");
// ダイアログの作成
AlertDialog.Builder builder = new AlertDialog.Builder(getActivity());
builder.setView(customAlertView)
.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