简体   繁体   English

如何禁用外部触摸以隐藏DialogPreference

[英]How to disable outside touching to hide DialogPreference

i'm developing a custom DialogPreference. 我正在开发自定义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. 我知道Dialog有方法setCanceledOnTouchOutside(boolean cancel) ,这是我需要的,但DialogPreference不是。

in onBindDialogView i try: onBindDialogView我尝试:

getDialog().setCanceledOnTouchOutside(true);

but getDialog() returns null . 但是getDialog()返回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. 您可以在显示对话框之前访问AlerDialog.Builder There you can specify builder.setCancelable(false) . 您可以在builder.setCancelable(false)指定builder.setCancelable(false) Probably in such way you can achieve desire behavior. 大概可以通过这种方式实现欲望行为。

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

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 触摸外部时,ShowCaseView不会隐藏 - ShowCaseView does not hide when touching outside 在DialogPreference中隐藏默认按钮 - Hide default buttons in DialogPreference 如何在Android中的自定义DialogPreference中隐藏取消按钮? - How do I hide the cancel button in a custom DialogPreference in Android? 如何检测onTouch()外部是否有东西在触摸/不触摸屏幕? - How do I detect if something is touching/not touching the screen outside of onTouch()? 在触摸外部编辑文本区域时隐藏android中的键盘 - Hide keypad in android while touching outside Edit Text Area 如何在触摸PopupWindow的外部区域时将其关闭? - How to dismiss the PopupWindow on touching outside area of it? 如何在触摸特定视图时禁用viewpager适配器? - how to disable viewpager adapter on touching specific views? 如何以编程方式创建DialogPreference? - How to create a DialogPreference programatically? 如何禁止用户关闭触摸它外面的警报对话框? - How to forbid user to close alert dialog touching outside it? Android:如何在触摸外部时关闭 DatePicker DialogFragment? - Android: how to dismiss a DatePicker DialogFragment when touching outside?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM