popupWindow 및 사용자 지정 레이아웃이있는 종류의 popupMenuItem을 만들려고합니다.이벤트 열기/닫기 popupWindow
나는 그것을 클릭하면 popupWindow를 보여주는 버튼이있다. 그리고이 팝업 창을 한 번 더 클릭하거나 popupWindow 외부를 클릭하면이 팝업 창을 닫으려고 트리거 및 이벤트를하고 싶습니다.
하지만 지금은 작동하지 않지만 내 setTouchInterceptor가 트리거되지 않습니다.이 문제를 해결할 생각이 있습니까?
이 popupWindow가 열릴 때마다 setOutsideTouchable (true)을 사용하여 다른 모든 UI 요소에 액세스 할 수 없습니다. 여기
내 코드 :
- popupMenuImageView 내 드롭 다운 버튼 (실제로는 이미지 뷰) 내 팝업 창을 보여줍니다
popupWindow 내 PopupWindod 개체에 대한 내 전역 변수. 또한
popupMenuImageView = (ImageView) getView().findViewById(R.id.popup_menu_imageView); popupMenuImageView.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { if (popupWindow == null) { int width = 375; int height = 240; TableLayout tableLayout = (TableLayout) getView().findViewById(R.id.custom_popup_menu_id); LayoutInflater layoutInflater = (LayoutInflater) getActivity().getSystemService(Context.LAYOUT_INFLATER_SERVICE); View layout = layoutInflater.inflate(R.layout.custom_popup_menu, tableLayout); popupWindow = new PopupWindow(layout, width, height, true); popupWindow.setOutsideTouchable(true); popupWindow.setFocusable(true); popupWindow.setTouchInterceptor(new View.OnTouchListener() { @Override public boolean onTouch(View v, MotionEvent event) { if(event.getAction()==MotionEvent.ACTION_OUTSIDE){ popupWindow.dismiss(); return true; } return false; } }); } popupWindow.showAsDropDown(popupMenuImageView); } });
내가 너무 작동하지 않았다이 시도했습니다
popupMenuImageView = (ImageView) getView().findViewById(R.id.popup_menu_imageView);
createMenuItem();
popupMenuImageView.setOnClickListener(eventOpenCloseMenuItem);
View.OnClickListener eventOpenCloseMenuItem = new View.OnClickListener(){
@Override
public void onClick(View v) {
if (isShowing) {
popupWindow.showAsDropDown(popupMenuImageView);
isShowing = false;
}else{
popupWindow.dismiss();
}
}
};
개인 무효 createMenuItem을() {
if (popupWindow == null) { int width = 375; int height = 240; TableLayout tableLayout = (TableLayout) getView().findViewById(R.id.custom_popup_menu_id); LayoutInflater layoutInflater = (LayoutInflater) getActivity().getSystemService(Context.LAYOUT_INFLATER_SERVICE); View layout = layoutInflater.inflate(R.layout.custom_popup_menu, tableLayout); popupWindow = new PopupWindow(layout, width, height, true); popupWindow.setOutsideTouchable(false); popupWindow.setFocusable(true); }
BitmapDrawable()에 대한 내 대답을 확인하시기 바랍니다 감가 상각하고, 대신 내가 ColorDrawable을 사용해야합니다() – AlexDG