Skip to content

Instantly share code, notes, and snippets.

@codeforfun-jp
Created January 29, 2021 05:49
Embed
What would you like to do?
Android Studio AlertDialog Customize 2
public class MyDialogFragment extends DialogFragment {
@NonNull
@Override
public Dialog onCreateDialog(@Nullable Bundle savedInstanceState) {
TextView titleView = new TextView(getActivity());
titleView.setText("タイトル");
titleView.setTextSize(24);
titleView.setTextColor(Color.WHITE);
titleView.setBackgroundColor(getResources().getColor(R.color.alertBlue));
titleView.setPadding(20, 20, 20, 20);
titleView.setGravity(Gravity.CENTER);
AlertDialog.Builder builder = new AlertDialog.Builder(getActivity());
builder.setCustomTitle(titleView)
.setMessage("ここにメッセージを入力します。ここにメッセージを入力します。ここにメッセージを入力します。")
.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