1. 设置popupWindow的背景为60%透明ide
Window window = activity.getWindow();ui
WindowManager.LayoutParams lp = window.getAttributes();spa
lp.alpha = 0.6f;事件
window.setAttributes(lp);get
记得隐藏popupwindow的时候,须要恢复it
WindowManager.LayoutParams lp = window.getAttributes();
io
lp.alpha = 1f;event
window.setAttributes(lp);class
2.定位的问题gui
2.1 获取自定义view的宽高 ***
view.measure(LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT);
int viewWidth = view.getMeasuredWidth();
int viewHeight = view.getMeasuredHeight();
2.2 根据加载的view的宽高能够计算popupwindow相对guideView的位置了
popWindow.showAsDropDown(guideView, location[0], location[1]);
或者相对于整个屏幕的位置:
popWindow.showAtLocation(parent, Gravity.CENTER, 0, 0);
3.不加popWindow.setBackgroundDrawable(new BitmapDrawable()); popWondow不响应返回键事件 和 点击区域外事件。
4. PopupWindow出现以后,默认的是全部的操做都无效的,除了HOME键。并且是能够操做后面的
界面的。想要锁定后面的界面,很简单,只须要让PopupWindow是focusable的。
popupWindow.setFocusable(true);
5.获取点击区域外的事件
popWindow.setFocusable(true);
popWindow.setTouchable(true);
popWindow.setTouchInterceptor(new OnTouchListener() {
@Override
public boolean onTouch(View v, MotionEvent event) {
if (popWindow.isShow()) {
// 显示popWindow
return true;
}
return false;
}
});