I am trying to create a custom alert dialog with rounded corners using a dialog fragment, and I read that this can be achieved setting the STYLE_NO_FRAME constant to the setStyle method of the DialogFragment. I did that in the onCreate method, but I get the above mentioned RunTimeException. Any ideas on what might be wrong?
Here's my code:
public static class AlertDialogFragment extends DialogFragment {
private static final String DIALOG_NUMBER_KEY = "dialogNumber";
private int dNumber;
public static AlertDialogFragment newInstance(int dialogNumber) {
AlertDialogFragment mDialogFragment = new AlertDialogFragment();
// Supply dialogNumber input as an argument
Bundle args = new Bundle();
args.putInt(DIALOG_NUMBER_KEY, dialogNumber);
mDialogFragment.setArguments(args);
return mDialogFragment;
}
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setStyle(STYLE_NO_FRAME, android.R.style.Theme_Holo);
}
// Build AlertDialog using AlertDialog.Builder
@Override
public Dialog onCreateDialog(Bundle savedInstanceState) {
dNumber = getArguments().getInt(DIALOG_NUMBER_KEY);
AlertDialog.Builder adb = new AlertDialog.Builder(getActivity());
LayoutInflater inflater = getActivity().getLayoutInflater();
switch(dNumber) {
case DELETE_DIALOG:
adb.setView(inflater.inflate(R.layout.delete_record_dialog, null))
.setCancelable(true)
.create();
AlertDialog customDeleteDialog = adb.show();
Button okButton = (Button) customDeleteDialog.findViewById(R.id.ok);
Button cancelButton = (Button) customDeleteDialog.findViewById(R.id.cancel);
okButton.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View v) {
// some code here
}
});
cancelButton.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View v) {
dismiss();
}
});
return customDeleteDialog;
}