Reputation: 893
I have a custom DialogFragment (support library). I set the layout as @color/GhostWhite, problem is, I can't find a way to set the positive/negative button in the same color.
This is how I set the buttons:
builder.setView(view)
// Add action buttons
.setPositiveButton("Shout!", new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int id) {
//publishStory(/*shoutText.getText().toString()"woww");
mListener.onDialogPositiveClick(WagDialogFragment.this);
}
})
.setNegativeButton(R.string.cancel, new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int id) {
}
});
return builder.create();
Upvotes: 0
Views: 4520
Reputation: 132992
you can call getButton
with DialogInterface.BUTTON_POSITIVE
and DialogInterface.BUTTON_NEGATIVE
parameters for changing color of both buttons as:
Button okButton = alertDialog.getButton(DialogInterface.BUTTON_POSITIVE);
// set OK button color here
okButton.setBackgroundColor(R.color.GhostWhite);
Button noButton = alertDialog.getButton(DialogInterface.BUTTON_NEGATIVE);
// set NO button color here
noButton.setBackgroundColor(R.color.GhostWhite);
Upvotes: 5
Reputation: 93678
After you call create, you can call getButton on the AlertDialog returned and set the color on that button.
Upvotes: 1