-
-
Save codeforfun-jp/2a8b3954df0f41186c78e8c3384d4cf3 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
class MyDialogFragment : DialogFragment() { | |
override fun onCreateDialog(savedInstanceState: Bundle?): Dialog { | |
val dialog = activity?.let { | |
// カスタムレイアウトの用意 | |
val inflater = it.layoutInflater | |
val customDialogView = inflater.inflate(R.layout.custom_dialog, null) | |
// タイトル | |
val title = customDialogView.findViewById<TextView>(R.id.title) | |
title.text = "こんにちは!" | |
// 画像名 | |
val imageName = customDialogView.findViewById<TextView>(R.id.image_name) | |
imageName.text = "アイコン画像" | |
// メッセージ | |
val message = customDialogView.findViewById<TextView>(R.id.message) | |
message.text = "ここにメッセージを入力します。ここにメッセージを入力します。ここにメッセージを入力します。" | |
AlertDialog.Builder(it) | |
.setView(customDialogView) | |
.setPositiveButton("OK") { _, _ -> } | |
.create() | |
} | |
return dialog ?: throw IllegalStateException("アクティビティがNullです。") | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment