You need to call setModal(false) of mPopupMenu. It will call setFocusable of inner PopupWindow and allow you to get events in the background window.
ImageView On click not firing at the 2nd click
Question
I want to close a popup menu on clicking a imageview.But it is not working.
menuicon.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View v) {
if (f == 1) {
f = 0;
mPopupMenu.setContentWidth(ContactsActivity.this.getWindowManager()
.getDefaultDisplay()
.getWidth() / 2);
mAdapter.notifyDataSetChanged();
mPopupMenu.setAnchorView(menuicon);
mPopupMenu.show();
} else {
mPopupMenu.dismiss();
f = 1;
}
}
});
When I click the menuicon first time the popup menu is displaying correctly.But when i click for the 2nd time the menu is not closing.I debugged my code and found that the imageview is actually not firing roe 2nd time.menuicon is an imageview.And here is xml code:
<ImageView
android:id="@+id/menuicon"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerVertical="true"
android:src="@drawable/menuicon"
android:layout_alignParentRight="true"
android:layout_marginRight="10dp"
/>
Initial value of f is 1.
Solution
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow