0

I want to make a bold text in my activity and show it in a dialog box. I did it (I think) but I don't know how should I call it in my dialog box.

I'm trying in with HTML format:

    String text = "<b>" + "My text" + "</b> " + "is bold";
    StringCharacterIterator tv = null;
    tv.setText(Html.fromHtml(text ));

Here it should work, but how can I call the "tv"?

I'm trying this way:

builder.setMessage(tv);

...but isn't working since the error is:

error: incompatible types: Spanned cannot be converted to String tv.setText(Html.fromHtml(text ));
Giovanni
  • 111
  • 2
  • 16

2 Answers2

0

You can create custom dialog box(example: How to create a Custom Dialog box in android?) and set your string like below.

String text = "<b>My text</b> is bold";
TextView tv = yourdialog.findViewById(R.id.ur_text_view_id);
tv.setText(Html.fromHtml(text));
  • Thanks, I'll try. But how can I set a TextView in a dialog box in Java and assign it an ID without creating a dialog layout? I would like to use the material design – Giovanni Jan 05 '21 at 17:23
0

I answer by myself:

builder.setMessage(Html.fromHtml("<b>Write something" + "</b> " + "here"));
Giovanni
  • 111
  • 2
  • 16