PopupWindow 设置全屏(覆盖状态栏)

        当 PopupWindow 想要设置成全屏时,如果宽高只设置成 match_parent ,是无法实现全屏的,因为状态栏无法被覆盖,对于低版本(小于等于21时)可以重新计算 popup 的高度,而对于高版本(大于21)系统提供了 setClippingEnabled 方法,设置方法如下:

private void setFullScreen() {

        //sdk > 21 解决 标题栏没有办法遮罩的问题

        if (Build.VERSION.SDK_INT > 21) {

                this.setClippingEnabled(false);

        } else {

                this.setHeight(ScreenUtil.getScreenHeight(context));

        }

}

源码中 setClippingEnabled 方法的注释如下:

Allows the popup window to extend beyond the bounds of the screen. By default the window is clipped to the screen boundaries. Setting this to false will allow windows to be accurately positioned.

If the popup is showing, calling this method will take effect only the next time the popup is shown or through a manual call to one of the {@link #update()} methods.

允许 popup window 超出屏幕范围。默认情况下,popup window 会被剪切到屏幕边界。此方法设置为 false 时,将允许 popup window 精准定位。

如果 popup 正在显示,只调用此方法,全屏效果不会立刻生效,该效果会在下次 popup window 显示时生效;如果需要本次显示时生效,该方法后需要再手动调用{@link #update()}方法才行。

作者备注:所以建议该方法在创建 popup window 时调用。毕竟 update 是要走重绘逻辑的。

©著作权归作者所有,转载或内容合作请联系作者
【社区内容提示】社区部分内容疑似由AI辅助生成,浏览时请结合常识与多方信息审慎甄别。
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。

推荐阅读更多精彩内容

  • pyspark.sql模块 模块上下文 Spark SQL和DataFrames的重要类: pyspark.sql...
    mpro阅读 13,169评论 0 13
  • rljs by sennchi Timeline of History Part One The Cognitiv...
    sennchi阅读 12,164评论 0 10
  • The Inner Game of Tennis W Timothy Gallwey Jonathan Cape ...
    网事_79a3阅读 14,289评论 3 20
  • 斜风细雨暮成雪, 闲庭红枫菊花残。 落魄江湖书终还, 快马加鞭未下鞍。 此书尽误郎中去, 漂泊何方谁慰安。 别来我...
    莫微阅读 1,267评论 1 2
  • 每当夜幕降临 梳理一天的思绪 便想起你,想起诗 这早已成了习惯 有时还怀疑可是相思成病 在梦里我问过你 清晨,我看...
    千好_68f8阅读 858评论 0 1