-
-
Save codeforfun-jp/83fabdd439a3bf2fdbbd482179096ed5 to your computer and use it in GitHub Desktop.
Android Studio AlertDialog Customize - Kotlin
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 titleView = TextView(activity) | |
titleView.text = "タイトル" | |
titleView.textSize = 24f | |
titleView.setTextColor(Color.WHITE) | |
titleView.setBackgroundColor(resources.getColor(R.color.blue)) | |
titleView.setPadding(20, 20, 20, 20) | |
titleView.gravity = Gravity.CENTER | |
val dialog = activity?.let { | |
AlertDialog.Builder(it) | |
.setCustomTitle(titleView) | |
.setMessage("ここにメッセージを入力します。ここにメッセージを入力します。ここにメッセージを入力します。") | |
.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