我有一个字符串如下:
<string name="ramadan_fasting_completion"><![CDATA[
You have made up all # days of fasting missed during Ramadan due to your period.
<br/><br/> If you enjoyed this experience, we\'d really appreciate it if you took a moment to
<font color=#5FCA1C>rate and review App</font> on the Play Store.
<br/><br/> Otherwise see you in Ramdan ?!]]></string>
当我以下面的方式将文本设置为textview时,它完全正常:
String congratulatoryDescription = getString(R.string.ramadan_fasting_completion);
setHtmlText(txtInformationDescription,congratulatoryDescription);
但是,如果我使用以下行修改字符串,然后在textview中设置它 “评分和评论应用”文字没有着色。
congratulatoryDescription = congratulatoryDescription.replace("#",totalDays);
congratulatoryDescription = congratulatoryDescription.replace("?",nextYear);
是正确的,但字体不是。
目前,我有一个使用spannable字符串的解决方法,但我对此不满意。您能否指导如何使用静态CDATA并处理字符串替换。
P.S:我知道我可以使用像%1s这样的字符串格式化程序,但因为我有同样的阿拉伯语版本,所以我无法正确使用格式化程序。