我的一个页面中用到了popupwindow,之前都没问题的,测试跑来说android7.0不对了,把原来的button挡住了(点击button弹出popupwindow)

重写showAsDropDown(view)就解决了。

public class SupportPopupWindow extends PopupWindow {

    public SupportPopupWindow(View contentView, int width, int height){
        super(contentView,width,height);
    }

    @Override
    public void showAsDropDown(View anchor) {
        if(Build.VERSION.SDK_INT == 24) {
            Rect rect = new Rect();
            anchor.getGlobalVisibleRect(rect);
            int h = anchor.getResources().getDisplayMetrics().heightPixels - rect.bottom;
            setHeight(h);
        }
        super.showAsDropDown(anchor);
    }

    @Override
    public void showAsDropDown(View anchor, int xoff, int yoff) {
        if(Build.VERSION.SDK_INT == 24) {
            Rect rect = new Rect();
            anchor.getGlobalVisibleRect(rect);
            int h = anchor.getResources().getDisplayMetrics().heightPixels - rect.bottom;
            setHeight(h);
        }
        super.showAsDropDown(anchor, xoff, yoff);
    }
}

 

相关文章:

  • 2022-12-23
  • 2021-11-17
  • 2021-08-06
  • 2021-08-04
  • 2021-05-12
  • 2021-08-28
  • 2022-12-23
  • 2022-01-19
猜你喜欢
  • 2021-04-10
  • 2021-12-30
  • 2021-12-11
  • 2022-12-23
  • 2021-06-21
  • 2021-08-10
相关资源
相似解决方案