-
-
Save codeforfun-jp/c6ccc3889e8b86607300548ffccb3050 to your computer and use it in GitHub Desktop.
Android Studio AlertDialog with HTML Link
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 html = "<p style=\"color:blue;\">テキストを入力します。</p>" + | |
"<p><ul><li>A</li><li>B</li><li>C</li></ul></p>" + | |
"<p>Google検索は<a href=\"http://google.com\">こちら</a></p>" | |
val dialog = activity?.let { | |
AlertDialog.Builder(it) | |
.setTitle("タイトル") | |
.setMessage(HtmlCompat.fromHtml(html, HtmlCompat.FROM_HTML_MODE_LEGACY)) | |
.setPositiveButton("OK") { _, _ -> } | |
.create() | |
} | |
return dialog ?: throw IllegalStateException("アクティビティがNullです。") | |
} | |
override fun onStart() { | |
super.onStart() | |
dialog?.findViewById<TextView>(android.R.id.message)?.movementMethod = LinkMovementMethod.getInstance() | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment