背景:
需要文本中部分顏色顯示為其它顏色,然后其中又分行壕探,我們首先想到的是直接拼接富文本冈钦。
String strEmail = "<font color='#FA670A'>" + email + "</font>";
String str = getString(R.string.txt_email_sent_tips, strEmail);
String replace = str.replace("\n", "<br>");
tvSentTip.setText(Html.fromHtml(replace));
其中只需要把 \n 替換成<br>就可以解決了,分行無效的問題李请。
String replace = str.replace("\n", "<br>");