Is there any way how to change default dialog buttons colour, or do I need to do custom dialog for that?
This is my dialog:
private void removeItem(final int position) {
/** Create dialog which ask if user is sure about delete name from list **/
AlertDialog.Builder builder = new AlertDialog.Builder(this);
builder.setTitle("Delete player");
builder.setIcon(R.mipmap.ic_launcher);
builder.setMessage("Do you want to delete player: \"" + mNameList.get(position).getText1() + "\"?")
.setCancelable(false)
/** If user click "ok" button, delete player from list and save changes **/
.setPositiveButton("OK", new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialogInterface, int i) {
mNameList.remove(position);
mAdapter.notifyItemRemoved(position);
saveData();
}
})
/** If user click "cancel" button, name won't delete from list **/
.setNegativeButton("Cancel", new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialogInterface, int i) {
dialogInterface.dismiss();
}
});
/** Create Dialog **/
AlertDialog alert = builder.create();
alert.show();
}
you can give
style
to your alertdialog
like this:And you can write this style in
xml
file like this:You can use the
MaterialAlertDialogBuilder
provided by the Material Components library which allows the creation of a MaterialAlertDialog
.Just use:
Then define your custom style, using the
buttonBarPositiveButtonStyle
andbuttonBarNegativeButtonStyle
attributes: