-
-
Save codeforfun-jp/81826d98772b7d6f3cb736147c4dcee7 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
public class MyDialogFragment extends DialogFragment { | |
@NonNull | |
@Override | |
public Dialog onCreateDialog(@Nullable Bundle savedInstanceState) { | |
String 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>"; | |
return new AlertDialog.Builder(requireActivity()) | |
.setTitle("タイトル") | |
.setMessage(Html.fromHtml(html)) | |
.setPositiveButton("OK", (dialog, id) -> { | |
}) | |
.create(); | |
} | |
@Override | |
public void onStart() { | |
super.onStart(); | |
AlertDialog alertDialog = (AlertDialog) getDialog(); | |
if (alertDialog != null) | |
((TextView) alertDialog.findViewById(android.R.id.message)).setMovementMethod(LinkMovementMethod.getInstance()); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment