Skip to content

Instantly share code, notes, and snippets.

@codeforfun-jp
Created December 19, 2023 07:58
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save codeforfun-jp/81826d98772b7d6f3cb736147c4dcee7 to your computer and use it in GitHub Desktop.
Save codeforfun-jp/81826d98772b7d6f3cb736147c4dcee7 to your computer and use it in GitHub Desktop.
Android Studio AlertDialog with HTML Link
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