/MyDialogFragment.java Secret
Created
January 29, 2021 11:28
Star
You must be signed in to star a gist
Android Studio AlertDialog with ImageView 2
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 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