android PopupWindow 底部阴影外部空间取消

PopupWindow   po;
public void init(){  //初始化
    po=new PopupWindow(this);
    View vs = LayoutInflater.from(this).inflate(R.layout.testlayout,null);
    Button viewById = (Button) vs.findViewById(R.id.btn12);
    viewById.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View v) {
            po.dismiss();
        }
    });
    po.setOnDismissListener(new PopupWindow.OnDismissListener() {
        @Override
        public void onDismiss() {
            Log.v("ta","setOnDismissListener");
            is=false;
            backgroundAlpha(1);
        }
    });
    po.setContentView(vs);
  //  po.setOutsideTouchable(false);
    po.setWidth(ViewGroup.LayoutParams.MATCH_PARENT);
    po.setHeight(ViewGroup.LayoutParams.WRAP_CONTENT);

}
boolean  is =false;  //禁止分发事件
    @Override
    public boolean dispatchTouchEvent(MotionEvent ev) {
        Log.v("ta","dispatchTouchEvent");
        if (is){
            return false;
        }
        return super.dispatchTouchEvent(ev);
    }
public void backgroundAlpha(float bgAlpha)  //阴影改变
{
    WindowManager.LayoutParams lp = getWindow().getAttributes();
    lp.alpha = bgAlpha; //0.0-1.0
    getWindow().setAttributes(lp);
}

你可能感兴趣的:(android)