Skip to content

Instantly share code, notes, and snippets.

@jiangecho
Created May 9, 2016 13:09
Show Gist options
  • Save jiangecho/db152c5065080dac16932ea97aa06ecc to your computer and use it in GitHub Desktop.
Save jiangecho/db152c5065080dac16932ea97aa06ecc to your computer and use it in GitHub Desktop.
popup menu window
private PopupWindow popTrainMenu() {
LayoutInflater inflater = LayoutInflater.from(this);
View view = inflater.inflate(R.layout.train_popwindow_menu, null);
Display display = getWindowManager().getDefaultDisplay();
Point size = new Point();
display.getSize(size);
int width = size.x;
int height = size.y;
Log.v("zxy", "width=" + width + ",height=" + height);
PopupWindow popWindow = new PopupWindow(view, 2 * width / 5, ViewGroup.LayoutParams.WRAP_CONTENT, true);
popWindow.setBackgroundDrawable(new BitmapDrawable());//设置PopupWindow的背景为一个空的Drawable对象,如果不设置这个,那么PopupWindow弹出后就无法退出了
popWindow.setOutsideTouchable(true);
WindowManager.LayoutParams params = getWindow().getAttributes();
params.alpha = 0.8f;
getWindow().setAttributes(params);
popWindow.setOnDismissListener(() -> {
WindowManager.LayoutParams params1 = getWindow().getAttributes();
params1.alpha = 1.0f;
getWindow().setAttributes(params1);
});
//popWindow.showAtLocation(titleBarLayout, Gravity.TOP | Gravity.RIGHT, 20, titleBarLayout.getHeight() + Utils.getStatusBarHeight(this) - 10);
//popWindow.showAsDropDown(rightTextView);
return popWindow;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment