0
Я хочу сделать о диалоге в моем приложении, и я хочу иметь кнопку диалога по умолчанию, и я решил использовать DialogFragment, так что я сделал это, как этотDialogFragment с отрицательной кнопкой
public class AboutDialog extends DialogFragment {
public AboutDialog() {
// Empty constructor for fragment
}
@Override
@NonNull
public Dialog onCreateDialog(Bundle savedInstanceState) {
AlertDialog.Builder builder = new AlertDialog.Builder(getActivity());
builder.setTitle("About");
builder.setNegativeButton("Close", new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int which) {
dismiss();
}
});
return builder.create();
}
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
View rootView = inflater.inflate(R.layout.about_dialog, container);
getDialog().setTitle(getString(R.string.action_about));
return rootView;
}
}
затем вызвать его из деятельности, как этот
AboutDialog about = new AboutDialog();
about.show(getSupportFragmentManager(), null);
, а затем я получаю эту ошибку
android.util.AndroidRuntimeException: requestFeature() must be called before adding content
Как исправить это?
Возможно, вы отправите код своей активности. –
Что именно из деятельности? Это вызывается в onOptionsItemSelected –
oncreate код вашей деятельности –