在android中的弹出对话框中禁用背景触摸

时间:2013-01-22 13:02:21

标签: android

enter image description here在我的代码中,我在弹出视图中显示警告。但当我触摸任何背景按钮时,它们都会启用。我想禁用背景触摸。 以下是我的代码。请检查一下。

LayoutInflater inflater = (LayoutInflater) getSystemService(Context.LAYOUT_INFLATER_SERVICE);
View popuplayoutReject = inflater.inflate(R.layout.popup_reject_request, (ViewGroup) findViewById(R.id.popup_element));
final PopupWindow popUpReject = new PopupWindow(popuplayoutReject, WindowManager.LayoutParams.WRAP_CONTENT,
        WindowManager.LayoutParams.WRAP_CONTENT, false);
ImageButton btnPopupReject_Ok, btnPopUpReject_Cancel;
TextView txtRequestRejectMessage = (TextView) popuplayoutReject.findViewById(R.id.errorMessage);
txtRequestRejectMessage.setText(getResources().getString(R.string.AddEntryNotSaved));
btnPopupReject_Ok = (ImageButton) popuplayoutReject.findViewById(R.id.btnPopup_Yes);
btnPopupReject_Ok.setImageResource(R.drawable.yes_button);

btnPopupReject_Ok.setOnClickListener(new OnClickListener() {
    @Override
    public void onClick(View v) {
       finish();
    }
});

btnPopUpReject_Cancel = (ImageButton) popuplayoutReject.findViewById(R.id.btnPopUp_No);
btnPopUpReject_Cancel.setImageResource(R.drawable.no_button);
btnPopUpReject_Cancel.setOnClickListener(new OnClickListener() {
    @Override
    public void onClick(View v) {
        popUpReject.dismiss();
    }
});
popUpReject.showAtLocation(popuplayoutReject, Gravity.CENTER, 0, 0);            

2 个答案:

答案 0 :(得分:1)

刚刚完成实施

final PopupWindow popUpReject = new PopupWindow(popuplayoutReject, WindowManager.LayoutParams.FILL_PARENT,
                            WindowManager.LayoutParams.FILL_PARENT, false);
                    popUpReject.setOutsideTouchable(false);

答案 1 :(得分:-1)

您的代码

 final PopupWindow popUpReject = new PopupWindow(popuplayoutReject, WindowManager.LayoutParams.WRAP_CONTENT,WindowManager.LayoutParams.WRAP_CONTENT, false);

固定代码

 final PopupWindow popUpReject = new PopupWindow(popuplayoutReject, WindowManager.LayoutParams.WRAP_CONTENT,WindowManager.LayoutParams.WRAP_CONTENT, true);