Android11 悬浮窗扩展到状态栏/虚拟导航栏显示

旧的FLAG_LAYOUT_INSET_DECOR、FLAG_LAYOUT_ATTACHED_IN_DECOR已经废弃,android R开始新的接口是android.view.WindowManager.LayoutParams#setFitInsetsTypes(接口如下):
        static final int FIRST = 1 << 0;
        static final int STATUS_BARS = FIRST;
        static final int NAVIGATION_BARS = 1 << 1;
        static final int CAPTION_BAR = 1 << 2;

        static final int IME = 1 << 3;

        static final int SYSTEM_GESTURES = 1 << 4;
        static final int MANDATORY_SYSTEM_GESTURES = 1 << 5;
        static final int TAPPABLE_ELEMENT = 1 << 6;

        static final int DISPLAY_CUTOUT = 1 << 7;

        static final int LAST = 1 << 8;
        static final int SIZE = 9;
        static final int WINDOW_DECOR = LAST;

        /**
         * Specifies types of insets that this window should avoid overlapping during layout.
         *
         * @param types which types of insets that this window should avoid. The initial value of
         *              this object includes all system bars.
         */
        public void setFitInsetsTypes(@InsetsType int types) {
            mFitInsetsTypes = types;
            privateFlags |= PRIVATE_FLAG_FIT_INSETS_CONTROLLED;
        }
windowManager.addView时LayoutParams的type用TYPE_APPLICATION_OVERLAY,并且加上
if (android.os.Build.VERSION.SDK_INT >= android.os.Build.VERSION_CODES.R) {
    fitInsetsTypes = 0
}

//其他
//WindowInsets.Type.systemBars()
//WindowInsets.Type.navigationBars()
//WindowInsets.Type.statusBars()

即可实现悬浮窗扩展到状态栏或虚拟导航栏显示

评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值