Html.fromHtml(字符串)+断行问题 [英] Html.fromHtml(String) + Linebreak Problem

查看:160
本文介绍了Html.fromHtml(字符串)+断行问题的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想在一条警告消息,以显示与断行文字:

I'd like to display a text with a linebreak in an Alert Message:

private void showAbout() {
        AlertDialog.Builder builder = new AlertDialog.Builder(context);

        String message = "<b>Rechtlicher Hinweis:</b>\nLorem ipsum dolor sit amet, consectetur adipiscing elit. Sed a dolor sapien. Etiam arcu erat, lobortis sed vestibulum ut, adipiscing et enim. Nulla vestibulum volutpat dolor, non pellentesque purus imperdiet vitae. Aenean et elit vel erat consectetur pulvinar. Sed semper, ante vel elementum aliquet, dui urna scelerisque tortor, eu auctor lorem nunc adipiscing velit. Praesent eget libero diam, eget imperdiet sem. Vestibulum ante ipsum primis in faucibus orci luctus et ultrices posuere cubilia Curae.\n" + getVersionInfo();

        builder.setMessage(Html.fromHtml(message));
        builder.setCancelable(false);
        builder.setPositiveButton("Close", new DialogInterface.OnClickListener() {
            public void onClick(DialogInterface dialog, int id) {
                dialog.cancel();
            }
        });
        builder.setTitle("About"); 
        builder.setIcon(R.drawable.icon); 

        AlertDialog alert = builder.create(); 

        alert.show(); 
    }

不过这部作品或多或少精细,换行符

However this works more or less fine, the linebreaks

\\ n

不显示的。我已经尝试过更换 \\ n \\\\ñ甚至&LT; \\ BR&GT; ,但毫无效果。任何提示如何做到这一点?

aren't displayed at all. I already tried to replace \n by \\n or even <\br> but nothing worked. Any hints how to do this?

推荐答案

尝试&LT; BR /&GT; (注意斜杠的之后的标签名称再加上它是一个斜线,不是一个落后的)。

Try <br /> (note the slash is after the tag name plus it's a forward slash, not a backward one).

这篇关于Html.fromHtml(字符串)+断行问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆