在popupwindow使用过程中常有如下需求:
先新建一个popupwindow
View view = View.inflate(this, R.layout.popup, null);
mPopupWindow = new PopupWindow(view, ViewGroup.LayoutParams.WRAP_CONTENT, ViewGroup.LayoutParams.WRAP_CONTENT, true);
mPopupWindow.setFocusable(true);
点击边框以外popupwindow消失
方法一、
mPopupWindow.setBackgroundDrawable(new ColorDrawable(Color.TRANSPARENT));
方法二、
popupwindow点击后外部变色
参考
http://blog.youkuaiyun.com/qiuqingpo/article/details/42971719
<pre name="code" class="java"> mContentView.setBackgroundColor(getResources().getColor(R.color.popup_main_background));
// 也可以直接设置透明度
WindowManager.LayoutParams params=getWindow().getAttributes();
params.alpha=0.7f;
getWindow().setAttributes(params);
这里contentview来源:
mContentView = getLayoutInflater().inflate(R.layout.activity_onlinelearn,null);
setContentView(mContentView);