I have a AlertDialog
that displays a certain message that includes two variables, which are mail and pass , and I want to be able to assign a color to it. any idea how to do this ?
I leave you my AlertDialog
String correo=txtcorreo.getText().toString();
String pass=txtpass.getText().toString();
AlertDialog.Builder alertDialogBuilder = new AlertDialog.Builder(AddCuentaExpositor.this);
alertDialogBuilder.setMessage("¿Esta seguro que desea crear la siguiente cuenta "+ correo + " con contraseña "+pass);
alertDialogBuilder.setPositiveButton("Si",
new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface arg0, int arg1) {
final String email=txtcorreo.getText().toString();
final String password=txtpass.getText().toString();
new Asyncinsert().execute(email,password);
}
});
alertDialogBuilder.setNegativeButton("No",
new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface arg0, int arg1) {
}
});
AlertDialog alertDialog = alertDialogBuilder.create();
alertDialog.show();
}
There are several ways, but I think the simplest would be this, using the RGB color and applying a transformation of the html code, for example to change the color of the message text to red (
#FF0000
) it would be done in this way:The same can be applied to the title.
To change the color only to the variables
email
andpass
, it would be done in this way:You can actually use various types of html tags, for example if you want "Bold" text, simply use the
<b>
and containers</b>
, "italic" text<i>
and</i>
, larger text using<big>
and</big>
etc...:I add an example in code to document what was commented in the answer: