Skip to content

Instantly share code, notes, and snippets.

@pavelupward
Created February 3, 2018 13:23
Show Gist options
  • Save pavelupward/e0544063fe1ca3030c4db2cd65161286 to your computer and use it in GitHub Desktop.
Save pavelupward/e0544063fe1ca3030c4db2cd65161286 to your computer and use it in GitHub Desktop.
PopupWindow
private PopupWindow mPWMenu;
private LinearLayout mLMenu;
private float sD;
private Context appContext;
private void showPopupWindow() {
mLMenu = (LinearLayout) appContext.LayoutInflater().inflate(R.layout.layer_menu, null);
mLMenu.setFocusableInTouchMode(true);
mPWMenu = new PopupWindow(mLMenu, (int) (260*sD), WindowManager.LayoutParams.WRAP_CONTENT, true);
mPWMenu.setAnimationStyle(R.style.Animations_PopDownMenu);
mPWMenu.setBackgroundDrawable(new BitmapDrawable()); // Without this line ACTION_OUTSIDE events are not triggered.
mPWMenu.getContentView().setOnKeyListener(new View.OnKeyListener() {
@Override
public boolean onKey(View v, int keyCode, KeyEvent event) {
if (keyCode == KeyEvent.KEYCODE_MENU && event.getRepeatCount() == 0 && event.getAction() == KeyEvent.ACTION_UP) {
mPWMenu.dismiss();
return true;
}
return false;
}
});}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment