可能重複:
How to dismiss the dialog with click on outside of the dialog?點擊彈出之外予以駁回
我如何可以點擊彈出窗口以外辭退呢?
這裏是我的代碼:
cell.setOnClickListener(new OnClickListener(){
/*This code is in a separate class so I needed to use ctx as context
*and the string "layout_inflater" because it was not recognizing
*LAYOUT_INFLATER_SERVICE*/
@Override
public void onClick(View arg0) {LayoutInflater layoutInflater =
(LayoutInflater)ctx.getSystemService("layout_inflater");
View popupView = layoutInflater.inflate(R.layout.popup_window, null);
final PopupWindow popupWindow = new PopupWindow(popupView,
LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT);
popupWindow.showAtLocation(newParentLayout, Gravity.CENTER, 0, 0);
}
我也嘗試添加了這一切,但沒有結果。
popupWindow.setTouchable(true);
popupWindow.setFocusable(true);
popupWindow.setOutsideTouchable(true);
Drawable bg = ctx.getResources().getDrawable(R.drawable.popup_bg);
popupWindow.setBackgroundDrawable(bg);
我不知道。任何幫助?
編輯添加:主佈局是一個ViewPager/PagerAdapter,如果這會影響任何東西?
@ Eng.Fouad該解決方案是用於對話框,這是一個彈出窗口。 –