Skip to content

Instantly share code, notes, and snippets.

@dynoChris
Created January 27, 2019 19:46
Show Gist options
  • Save dynoChris/394f5d04a72dcc549d255e04fdcab6b9 to your computer and use it in GitHub Desktop.
Save dynoChris/394f5d04a72dcc549d255e04fdcab6b9 to your computer and use it in GitHub Desktop.
How to change background color of Alert Dialog in Android
AlertDialog.Builder builder = new AlertDialog.Builder(new ContextThemeWrapper(getActivity(), R.style.AlertDialogCustom));
AlertDialog alertDialog = builder.create();
alertDialog.setTitle(getResources().getString(R.string.reset_to_default));
alertDialog.setMessage(getResources().getString(R.string.you_sure_to_reset));
alertDialog.setButton(AlertDialog.BUTTON_POSITIVE, getResources().getString(R.string.yes),
new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int which) {
dialog.dismiss();
}
});
alertDialog.setButton(AlertDialog.BUTTON_NEGATIVE, getResources().getString(R.string.cancel),
new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int which) {
dialog.dismiss();
}
});
alertDialog.show();
<!-- Alert Dialog Theme -->
<style name="AlertDialogCustom" parent="@android:style/Theme.Dialog">
<item name="android:background">@color/colorBackground</item>
</style>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment