Android 全屏悬浮窗适配(悬浮窗沉浸式)

本文探讨了Android高版本下如何突破WindowsManager限制,实现悬浮窗沉浸状态栏。通过详解权限、WindowType和关键代码,教你如何设置透明、权限和参数,以及利用LayoutParams布局策略来达到沉浸效果,包括状态栏高度的获取方法。
  • 前言
    由于Android 高版本的类型限制,如果我们使用WindowsManager 做悬浮窗,会被限制在当前窗口内容中。而当前窗口大小会限制在状态栏和导航栏之间,所以会导致悬浮窗沉浸不了状态栏。

高版本windowsmanager 限制 源码


        if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) {
   
   //6.0+
            mParams.type = WindowManager.LayoutParams.TYPE_APPLICATION_OVERLAY;

        } else {
   
   
            mParams.type = WindowManager.LayoutParams.TYPE_SYSTEM_ALERT;
        }

        /**
         * Window type: Application overlay windows are displayed above all activity windows
         * (types between {@link #FIRST_APPLICATION_WINDOW} and {@link #LAST_APPLICATION_WINDOW})
         * but below critical system windows like the status bar or IME.
         * <p>
         * The system may change the position, size, or visibility of these windows at anytime
         * to reduce visual clutter to the user and also manage resources.
         * <p>
         * Requires {@link android.Manifest.permission#SYSTEM_ALERT_WINDOW} permission.
         * <p>
         * The system will adjust the importance of processes with this window type to reduce the
         * chance o
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值