首先两个方法 private void showPopupWindow(View view, View rootView){
PopupWindow popupWindow = new PopupWindow(view, LinearLayout.LayoutParams.WRAP_CONTENT,LinearLayout.LayoutParams.WRAP_CONTENT);
popupWindow.setBackgroundDrawable(new BitmapDrawable());
popupWindow.setFocusable(true);
popupWindow.setOutsideTouchable(true);
// popupWindow.showAsDropDown(rootView);
popupWindow.showAtLocation(rootView, Gravity.CENTER,0,0);
setAlpha(0.8f);
popupWindow.setOnDismissListener(new PopupWindow.OnDismissListener() {
@Override
public void onDismiss() {
setAlpha(1.0f);
}
});
}
private void setAlpha(float f){
WindowManager.LayoutParams layoutParams = this.getWindow().getAttributes();
layoutParams.alpha = f;
this.getWindow().setAttributes(layoutParams);
}
popupwindow有两种show的方法,一种是showAsDropDown,一种是showAtLocation,需要两个view支持。
调用的时候吧pop的view和父view传进来即可,
View view = LayoutInflater.from(this).inflate(R.layout.pop_layout, null);
View rootview = LayoutInflater.from(this).inflate(R.layout.activity_loading, null);
弹出来的布局如果有点击事件什么的,需要view.findviewbyid,找到对应控件进行操作。
转载请注明原文地址: https://ju.6miu.com/read-677439.html