gif不是那么清晰,凑合着看哈O(∩_∩)O
//以下是如何实现自定义弹出窗口,mView就是你想要展现的视图
View mView = LayoutInflater.from(this).inflate(R.layout.click_booth_floating, null);
WindowManager wm = this.getWindowManager();
int width = wm.getDefaultDisplay().getWidth();
//设置窗口的宽度
mView.setMinimumWidth(width);
/* 下面是对PopupWindow四个参数的详细介绍
* @param contentView the popup's content
* @param width the popup's width
* @param height the popup's height
* @param focusable true if the popup can be focused, false otherwise
*/
PopupWindow popupWindow = new PopupWindow(mView, ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.WRAP_CONTENT , true);
//获取AppBarLayout
AppBarLayout appBar = (AppBarLayout) findViewById(R.id.map_activity_app_bar_layout);
//点击popupwindow之外的地方,popupwindow消失
popupWindow.setOutsideTouchable(true);
//由于Android 版本差异性,在不需要背景的情况下设置背景为透明
popupWindow.setBackgroundDrawable(new ColorDrawable(getResources().getColor(R.color.map_page_background)));
//从appbar位置向下滑出PopupWindow
popupWindow.showAsDropDown(appBar);