直播商城源码,PopupWindow菜单在ListView中显示
直播商城源码,PopupWindow菜单在ListView中显示
private PopupWindow mOperaPopup;
private void showMenuPopup(View anchor)
{
if(mOperaPopup==null)
{
View popupView=View.inflate(mContext,R.layout.popup_opera_subject,null);
mOperaPopup=new PopupWindow(mContext);
mOperaPopup.setBackgroundDrawable(new ColorDrawable(
mContext.getResources().getColor(R.color.transparent)));
mOperaPopup.setContentView(popupView);
mOperaPopup.setFocusable(true);
mOperaPopup.setOutsideTouchable(true);
//ppw消息监听,让整体背景恢复到正常
mOperaPopup.setOnDismissListener(new PopupWindow.OnDismissListener() {
@Override
public void onDismiss() {
WindowManager.LayoutParams layoutParams=mActivity.getWindow().getAttributes();
layoutParams.alpha=1.0f;
mActivity.getWindow().setAttributes(layoutParams);
}
});
//手机返回键监听,让ppw消失
popupView.setOnKeyListener(new View.OnKeyListener() {
@Override
public boolean onKey(View v, int keyCode, KeyEvent event) {
if (keyCode == KeyEvent.KEYCODE_BACK) {
mOperaPopup.dismiss();
return true;
}
return false;
}
});
}
int offX=ScreenInfomationLoader.getInstance().dpToPx(107);//适配自定义偏移距离(根据具体布局)
//gravity是表示ppw相对于anchor的左边距还是右边距,x方向向右为正,y方法,向下为正
mOperaPopup.showAsDropDown(anchor,-offX,0,Gravity.LEFT);
WindowManager.LayoutParams layoutParams=mActivity.getWindow().getAttributes();
layoutParams.alpha=0.8f;//通过透明度控制整体背景变暗,值越大,越透明;值越小,越暗。
mActivity.getWindow().setAttributes(layoutParams);
}
以上就是 直播商城源码,PopupWindow菜单在ListView中显示,更多内容欢迎关注之后的文章