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;
}
});