简体   繁体   中英

How to disable outside touching to hide DialogPreference

i'm developing a custom DialogPreference.

When user clicks outside the dialog, it is cancelled and i need to avoid this.

I know that Dialog has method setCanceledOnTouchOutside(boolean cancel) that is what i need but the DialogPreference not.

in onBindDialogView i try:

getDialog().setCanceledOnTouchOutside(true);

but getDialog() returns null .

How can i do? Can someone help me?

This is my class:

public class UpdatePreference extends DialogPreference implements View.OnClickListener{


    public UpdatePreference(Context context, AttributeSet attrs) {
        super(context, attrs);
        setPersistent(false);
        setDialogLayoutResource(R.layout.update_dialog_layout);
        setPositiveButtonText("");
        setNegativeButtonText("");
    }

    @Override
    protected void onBindDialogView(View view) {
        super.onBindDialogView(view);   
        //init my components
    }

    @Override
    protected void onDialogClosed(boolean positiveResult) {
        super.onDialogClosed(positiveResult);

    }

}

You can access AlerDialog.Builder before dialog will be shown. There you can specify builder.setCancelable(false) . Probably in such way you can achieve desire behavior.

@Override
protected void onPrepareDialogBuilder(Builder builder) {
    super.onPrepareDialogBuilder(builder);
    builder.setCancelable(false);
}

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM