popupwindow关于华为手机的适配

1.PopupWindow显示时使当前activity变暗:

  WindowManager.LayoutParams params = mContext.getWindow().getAttributes();
    params.alpha = 0.7f;
    if (params.alpha == 1) {
        mContext.getWindow().clearFlags(WindowManager.LayoutParams.FLAG_DIM_BEHIND);
        //不移除该Flag的话,在有视频的页面上的视频会出现黑屏的bug
    } else {
          mContext.getWindow().addFlags(WindowManager.LayoutParams.FLAG_DIM_BEHIND);
           //此行代码主要是解决在华为手机上半透明效果无效的bug
    }
    mContext.getWindow().setAttributes(params);

popupwindow关闭,恢复之前的透明度:

     mPopWindow.setOnDismissListener(new PopupWindow.OnDismissListener() {
        @Override
        public void onDismiss() {
           params.alpha = 1;
            mContext.getWindow().setAttributes(params);
            contentView.startAnimation(trans);
        }
    });

2.popupwidow触摸外部区域,自动消失关闭:

  mPopWindow.setBackgroundDrawable(new ColorDrawable(0x00000000));//关键代码
  mPopWindow.setOutsideTouchable(true);

3.华为手机虚拟键盘遮挡popupwindow问题:

  mPopWindow.setSoftInputMode(WindowManager.LayoutParams.SOFT_INPUT_ADJUST_RESIZE);

你可能感兴趣的:(动画,popupwindow的使用)