Html format tags ignored in Dialog
A few Html tags in the strings.xml file are rendered properly when used in a TextView, so for example, the following text resource would appear bold:
<string name="example_text"><b>This text is bold</b></string>
However, if the same text is used in a custom Dialog, the formatting is ignored.
Doe开发者_如何转开发s anyone know how to format part of the text in a scrollview within a dialog box?
You could format with HTML by using a WebView in the dialog:
strings.xml
<string name="example_text" formatted ="false"><![CDATA[ <strong> Example Text </strong> ]]></string>
java
String string = getString(R.string.example_text);
WebView wv = new WebView (getBaseContext());
wv.loadData(string, "text/html", "utf-8");
wv.setBackgroundColor(Color.WHITE);
wv.getSettings().setDefaultTextEncodingName("utf-8");
new AlertDialog.Builder(this)
.setCancelable(false)
.setView(wv)
.setNeutralButton("OK", new DialogInterface.OnClickListener(){
@Override
public void onClick(DialogInterface dialog, int which) {
dialog.cancel();
}
})
.show();
精彩评论