2

I just saw this post (How can I change the color of AlertDialog title and the color of the line under it) and I doubt if my title get a variable ... how I can use the first solution to change the color?

This is my code:

   AlertDialog.Builder dialogo = new AlertDialog.Builder(ListadoBC.this);
   dialogo.setTitle("¡"+listaBC.get(arg2).getFragilidad()+" !\n"+"¿Ha seguido esta recomendación?");

And I want that this sentence ("¡"+listaBC.get(arg2).getFragilidad()+" !\n") appears in red using something like this () alert.setTitle( Html.fromHtml("<font color='#FF7F27'>Set IP Address</font>"));... is it possible?

Community
  • 1
  • 1
wiki
  • 299
  • 4
  • 16

1 Answers1

1

Without Custom Dialog its possible, See below code.

Alert.setTitle(getHtmlFormatString("<font color='#FF7F27'>Set IP Address</font>");

getHtmlFormatString() is method to convert htmlTag to String.

 private Spanned getHtmlFormatString(String htmlTag)
{
    Spanned result;
    if (android.os.Build.VERSION.SDK_INT >= android.os.Build.VERSION_CODES.N) {
        result = Html.fromHtml(htmlTag,Html.FROM_HTML_MODE_LEGACY);
    } else {
        result = Html.fromHtml(htmlTag);
    }
    return result;
}
Magesh Pandian
  • 8,789
  • 12
  • 45
  • 60