What i am doing: I am creating a custom alert dialog
What i am trying to do: along with below code, How to change the color of action buttons in dialog(positive and negative)
@Override
public Dialog onCreateDialog(Bundle savedInstanceState) {
AlertDialog.Builder builder = new AlertDialog.Builder(getActivity());
// Get the layout inflater
LayoutInflater inflater = getActivity().getLayoutInflater();
// Inflate and set the layout for the dialog
// Pass null as the parent view because its going in the dialog layout
builder.setView(inflater.inflate(R.layout.dialog_signin, null))
// Add action buttons
.setPositiveButton(R.string.signin, new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int id) {
// sign in the user ...
}
})
.setNegativeButton(R.string.cancel, new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int id) {
LoginDialogFragment.this.getDialog().cancel();
}
});
return builder.create();
you can do it like this-
You can use the setOnShowListener method of the AlertDialog to get the buttons and apply a different color and their own listeners, here you have an example in Kotlin:
you can overwrite onStart method to get handle of all the buttons (Positive, Negative and Neutral).