Created
February 3, 2018 13:23
-
-
Save pavelupward/e0544063fe1ca3030c4db2cd65161286 to your computer and use it in GitHub Desktop.
PopupWindow
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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