4

I want to show message of AlertDialog in two separate lines and text in one line in bold style and in next line simple text (without any style).

Now If I am performing break line with bold text , lines are break'd but text is not showing bold. Why ? can anyone help me.

Code :

AlertDialog.Builder alertDialog = new AlertDialog.Builder(this);
    alertDialog.setTitle("Alert");
    Spanned s1 = Html.fromHtml("<b>" + "Text in Bold"+ "</b>");
    String s2 = "Normal Text";
    alertDialog.setMessage(s1+ "\n" + s2);
AlertDialog dialog = alertDialog.create();
dialog.show();
Kapil Rajput
  • 11,429
  • 9
  • 50
  • 65
  • Use SpannableStringBuilder instead of string, that may help you – Bethan Dec 23 '16 at 12:03
  • Try this link, it definitely will help you. http://stackoverflow.com/questions/4897349/android-coloring-part-of-a-string-using-textview-settext – Bethan Dec 23 '16 at 12:10

2 Answers2

6

Could you please try this:

AlertDialog.Builder alertDialog = new AlertDialog.Builder(this);
    alertDialog.setTitle("Alert");
    String s1 = "<b>" + "Text in Bold"+ "</b>";
    String s2 = "Normal Text";
    Spanned strMessage = Html.fromHtml(s1+  "<br>" + s2);
    alertDialog.setMessage(strMessage);
AlertDialog dialog = alertDialog.create();
dialog.show();
Kapil Rajput
  • 11,429
  • 9
  • 50
  • 65
ziLk
  • 3,120
  • 21
  • 45
0

Use \n to break the line.

AlertDialog.Builder alertDialog = new AlertDialog.Builder(this);
alertDialog.setTitle("Alert");
String s1 = "<b>" + "Text in Bold"+ "</b>";
String s2 = "Normal Text";
Spanned strMessage = Html.fromHtml(s1+  "\n" + s2);
alertDialog.setMessage(strMessage);
AlertDialog dialog = alertDialog.create();
dialog.show();
Shagun Verma
  • 163
  • 1
  • 9