Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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.

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

like image 782
John J Smith Avatar asked Jul 08 '11 20:07

John J Smith


1 Answers

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(); 
like image 117
Neil Hoff Avatar answered Sep 22 '22 22:09

Neil Hoff