0
밖에 걸 때 PopupWindow
을 어떻게 무시합니까? 내가 따라팝업창을 닫는 방법
private void initiatePopupWindow(View viewButton) {
LayoutInflater inflater = (LayoutInflater) MainActivity.this
.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
View view = inflater.inflate(R.layout.popup_layout, null);
mPopupWindow = new PopupWindow(this);
mPopupWindow.setContentView(view);
mPopupWindow.setWidth(WindowManager.LayoutParams.MATCH_PARENT);
mPopupWindow.setHeight(WindowManager.LayoutParams.WRAP_CONTENT);
mPopupWindow.showAsDropDown(viewButton);
// final PopupWindow pw = new PopupWindow(inflater.inflate(
// R.layout.popup_layout, null, false), LinearLayout.LayoutParams.WRAP_CONTENT, LinearLayout.LayoutParams.MATCH_PARENT, true);
// pw.showAtLocation(view, Gravity.BOTTOM, 0, view.getHeight());
ListView moreOptions = (ListView) mPopupWindow.getContentView().findViewById(R.id.list_view);
String[] options = new String[]{"Settings", "Feedback", "Contribute", "DashClock Integration", "Tutorial", "DashClock Integration", "Tutorial", "DashClock Integration", "Tutorial", "DashClock Integration", "Tutorial", "DashClock Integration", "Tutorial"};
final ArrayList<String> moreOptionsList = new ArrayList<String>();
for (int i = 0; i < options.length; ++i) {
moreOptionsList.add(options[i]);
}
ArrayAdapter<String> moreOptionsAdapter = new ArrayAdapter<String>(this,
android.R.layout.simple_list_item_1,
moreOptionsList);
moreOptions.setAdapter(moreOptionsAdapter);
// mPopupWindow.setBackgroundDrawable(new ColorDrawable(ContextCompat.getColor(this, android.R.color.transparent)));
mPopupWindow.setFocusable(true);
mPopupWindow.setBackgroundDrawable(new ColorDrawable());
mPopupWindow.setOutsideTouchable(true);
// mPopupWindow.setTouchInterceptor(new View.OnTouchListener() {
// @Override
// public boolean onTouch(View v, MotionEvent event) {
// if (event.getAction() == MotionEvent.ACTION_OUTSIDE){
// mPopupWindow.dismiss();
// }
// return false;
// }
// });
}
:
이
내 코드입니다mPopupWindow.setFocusable(true);
mPopupWindow.setBackgroundDrawable(new ColorDrawable());
mPopupWindow.setOutsideTouchable(true);
그러나 그것은 작동하지 않습니다. 어떻게 해결할 수 있습니까?
이 문제를 해결하려면 mPopupWindow.setBackgroundDrawable (새 BitmapDrawable (getResources(), "")))에서 showAsDropDown (viewButton)을 삽입하십시오. mPopupWindow.setOutsideTouchable (true); – JackieChung