Вам нужно вызвать create()
на объекте конструктора вместо show()
, чтобы создать AlertDialog
объект. Затем вы можете изменить любую часть вашего диалога, например, область кнопок, используя setOnShowListener
. этот слушатель вызывается после создания вашего диалога, поэтому мы используем его, чтобы избежать исключения nullpointer.
final AlertDialog dialog = new AlertDialog.Builder(MainActivity.this,R.style.MyDialogTheme)
.setCustomTitle(custom_dialog_header)
.setSingleChoiceItems(items, -1, new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialogInterface, int selectedIndex) {
int selectedItem = selectedIndex;
}
})
.setPositiveButton("Confirm", new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int linkID) {
String[] files = links.split(",");
}
})
.setNegativeButton("Cancel", null)
.create();
dialog.setOnShowListener(new DialogInterface.OnShowListener() {
@Override
public void onShow(DialogInterface d) {
// to change background of positive button
dialog.getButton(AlertDialog.BUTTON_POSITIVE).setBackgroundColor(getResources().getColor(R.color.some_color));
// to change background of button area
ButtonBarLayout b = (ButtonBarLayout)(dialog.getButton(AlertDialog.BUTTON_POSITIVE).getParent());
b.setBackgroundColor(getResources().getColor(R.color.some_color));
}
});
dialog.show();