我实现了一个带有单选列表的DialogFragment,带有复选框的自定义视图以及这样的正面和负面按钮:
@Override
public Dialog onCreateDialog(Bundle savedInstanceState) {
AlertDialog.Builder builder = new AlertDialog.Builder(getActivity(), ThemeUtils.getDialogTheme(getActivity()));
LayoutInflater inflater = getActivity().getLayoutInflater();
View v = inflater.inflate(R.layout.simple_layout_with_checkbox, null);
builder.setTitle(getContext().getString(R.string.categories))
.setSingleChoiceItems(categories, 0, new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int which) {
//...
}
});
builder.setPositiveButton(getContext().getString(R.string.apply), new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int which) {
//...
}
});
builder.setNegativeButton(R.string.cancel, null);
builder.setView(v);
return builder.create();
}
如您所见,按钮复选框已消失。我认为这个问题与listview高度有关,它没有为其他视图留出足够的空间。
我想摆脱这种行为并允许我的对话框完全显示(带按钮和复选框)。