2015-05-18

[Android] 在AlertDialog當中顯示HTML格式的字串. Show HTML String in a AlertDialog


Show HTML String in a AlertDialog.

But not all html tag is supported.
See HTML tags supported by TextView.
https://commonsware.com/blog/Android/2010/05/26/html-tags-supported-by-textview.html


/**
 * Show HTML String is AlertDialog
 */
static void showHtmlDialog(Context context, String title, String htmlString) {
    new AlertDialog.Builder(context)
            .setTitle(title)
            .setMessage(Html.fromHtml(htmlString))
            .setPositiveButton(android.R.string.ok, null)
            .show();
}



Usage :
showHtmlDialog(this, "This is HTML", "<html><body>This is HTML</body></html>");