1

I want to know if it is possible to change text colour within strings in Java?

I have a peice of text below within my alert dialog and basically what I like is for all the text that are in bold (), I want the colour of those text to be red whilst the rest of the text is black. Is this possible and if so how to implement?

    alertDialog.setMessage(Html.fromHtml("<b>Number of Human Players Required:</b>" + "<br/><br/>" +
 " 2" + "<br/><br/>" +
  "<b>Objective Of The Game:</b>" + "<br/><br/>" +
 "The objective of Tic Tac Toe is to get three in a row either in a vertical line, " +
                                    "horizontal line or diagonal line."

    )

Thanks,

Merlin
  • 185
  • 2
  • 14

1 Answers1

2

You can do something like this:

String s =  "<font color='red'><b>Number of Human Players Required:</b></font>" 
            + "<br/><br/>" + " 2" + "<br/><br/>" 
            + "<font color='blue'><b>Objective Of The Game:</b></font>" 
            + "<br/><br/>" 
            + "<font color='yellow'>The objective of Tic Tac Toe is to get three in a row either in a vertical line, " 
            + "horizontal line or diagonal line.</font>"

alertDialog.setMessage(Html.fromHtml(s));
Yahya
  • 13,349
  • 6
  • 30
  • 42