Invalid HTML tags in dialog

Several HTML tags in the strings.xml file display correctly when used in a TextView, therefore, for example, the following text resource will be allocated:

<string name="example_text"><b>This text is bold</b></string> 

However, if the same text is used in a user dialog, formatting is ignored.

Does anyone know how to format part of the text in a scroll in a dialog box?

+8
android formatting text dialog
source share
1 answer

You can format HTML using WebView in the dialog box:

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(); 
+8
source share

All Articles