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
我該如何解決這個問題?
您可以發佈您的活動代碼嗎? – 2014-09-19 09:13:22
活動究竟是什麼?這在onOptionsItemSelected中被調用 – 2014-09-19 09:14:32
oncreate您的活動的代碼 – 2014-09-19 09:19:38