ダイアログにリンクをつける

調べたら案外簡単だったのでご紹介。

String htmlText = "<a href=\"http://google.com\">google</a>";
CharSequence charSequence = Html.fromHtml(htmlText);
TextView tv = new TextView(this);
tv.setText(charSequence);
// これ重要!
tv.setMovementMethod(LinkMovementMethod.getInstance());

AlertDialog.Builder alertDialog = new AlertDialog.Builder(this);
alertDialog.setTitle("google home");
alertDialog.setView(tv);
alertDialog.setPositiveButton("OK", new DialogInterface.OnClickListener() {
    // 処理
}