gpt4 book ai didi

android - 如何禁用 Dialogfragment 在 android 上点击外部?

转载 作者:太空宇宙 更新时间:2023-11-03 12:14:45 48 4
gpt4 key购买 nike

我使用 extends DialogFragment

我想要对话框除外,禁止在 android 上点击。

我尝试了 setCanceledOnTouchOutside(true) 但它不起作用。

请检查我的来源。

public class QuestDialog extends DialogFragment {
private String mainMessage = "";
private View.OnClickListener positiveListener = null;
private View.OnClickListener negativeListener = null;

@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {

View view = inflater.inflate(R.layout.main_dialog, container, false);

TextView textView = (TextView) view.findViewById(R.id.main_msg);
textView.setText(mainMessage);

Button positiveBtn = (Button) view.findViewById(R.id.dialog_positive_btn);
Button negativeBtn = (Button) view.findViewById(R.id.dialog_negative_btn);

positiveBtn.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
dismiss();
if (positiveListener != null) {
positiveListener.onClick(view);
}
}
});
negativeBtn.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
dismiss();

if (negativeListener != null) [
negativeListener.onClick(view);
}
}
});
return view;
}

@Override
public Dialog onCreateDialog(Bundle savedInstanceState) {

Dialog dialog = super.onCreateDialog(savedInstanceState);
dialog.setCanceledOnTouchOutside(true);
dialog.requestWindowFeature(Window.FEATURE_NO_TITLE);

dialog.getWindow().setFlags(WindowManager.LayoutParams.FLAG_NOT_FOCUSABLE,
WindowManager.LayoutParams.FLAG_NOT_FOCUSABLE);
dialog.getWindow().addFlags(WindowManager.LayoutParams.FLAG_ALT_FOCUSABLE_IM |
WindowManager.LayoutParams.FLAG_KEEP_SCREEN_ON);

dialog.getWindow().getDecorView().setSystemUiVisibility(View.SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN
| View.SYSTEM_UI_FLAG_LAYOUT_STABLE
| View.SYSTEM_UI_FLAG_HIDE_NAVIGATION
| View.SYSTEM_UI_FLAG_FULLSCREEN
| View.SYSTEM_UI_FLAG_IMMERSIVE_STICKY
| View.SYSTEM_UI_FLAG_LAYOUT_HIDE_NAVIGATION);
return dialog;
}
public void setMessage(final String msg) {
mainMessage = new String(msg);
}

public void setPositiveButton(View.OnClickListener listener) {
positiveListener = listener;
}

这个。

如何在android上禁止点击外部的dialogfragment?

谢谢。

最佳答案

根据您的要求,您应该使用setCancelable(true)

Dialog dialog = super.onCreateDialog(savedInstanceState);
dialog.setCancelable(true);
dialog.setCanceledOnTouchOutside(true);
dialog.requestWindowFeature(Window.FEATURE_NO_TITLE);

关于android - 如何禁用 Dialogfragment 在 android 上点击外部?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/44018711/

48 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com