- 方法1:
- public class MyAlertDialogFragment extends DialogFragment {
- public static MyAlertDialogFragment newInstance(int title) {
- MyAlertDialogFragment frag = new MyAlertDialogFragment();
- Bundle args = new Bundle();
- args.putInt("title", title);
- frag.setArguments(args);
- return frag;
- }
- @TargetApi(11)
- @Override
- public Dialog onCreateDialog(Bundle savedInstanceState) {
- int title = getArguments().getInt("title");
- AlertDialog dialog = new AlertDialog.Builder(getActivity())
- .setIcon(R.drawable.ic_launcher)
- .setTitle(title)
- .setPositiveButton(R.string.alert_dialog_ok,
- new DialogInterface.OnClickListener() {
- public void onClick(DialogInterface dialog, int whichButton) {
- ((MainActivity)getActivity()).doPositiveClick();
- }
- }
- )
- .setNegativeButton(R.string.alert_dialog_cancel,
- new DialogInterface.OnClickListener() {
- public void onClick(DialogInterface dialog, int whichButton) {
- ((MainActivity)getActivity()).doNegativeClick();
- }
- }
- )
- .create();
- dialog.setCanceledOnTouchOutside(false);// 设置点击屏幕Dialog不消失
- return dialog;
- }
- }
- 方法2:在oncreate()方法中设置Dialog点击屏幕不可取消,实例代码如下
-
- @Override
- public void onCreate(Bundle icicle)
- {
- super.onCreate(icicle);
- this.setCancelable(false);// 设置点击屏幕Dialog不消失
- int style = DialogFragment.STYLE_NORMAL, theme = 0;
- setStyle(style,theme);
- }
设置Dialog点击屏幕不消失
最新推荐文章于 2024-06-20 08:17:37 发布