【发布时间】:2015-03-30 09:54:49
【问题描述】:
我在下面有一个 xml 字符串,其中包含 html 标记,例如粗体和超链接 href。
<string name"example"><b>%1$s</b> has been added to your clipboard and is valid until <b>%2$s</b><a href="http://www.google.com">Please see our +T\'s and C\'s+ </a> </string>
当我格式化字符串以动态添加一些值时,它会删除我定义的粗体文本和 href。
代码如下:
SimpleDateFormat simpleDateFormat = new SimpleDateFormat("dd-MM-yy");
Date date = new Date(text.getValidTo());
String text = String.format(getString(R.string_dialog_text), text.getCode(), simpleDateFormat.format(date), "£30");
然后我将它应用到警报对话框
AlertDialog.Builder builder = new AlertDialog.Builder(context);
builder.setNeutralButton(R.string.ok, onClickListener);
builder.setTitle(title);
builder.setMessage(text);
如果我不格式化文本并直接使用字符串资源,这很好用
【问题讨论】: