非Android标准模式

全屏应用(内容延伸到StatusBar后面),获取状态栏高度,并在顶部添加适当的空白

fun Context.getStatusBarHeight(): Int {    val resourceId = resources.getIdentifier("status_bar_height", "dimen", "android")    return if (resourceId > 0) {        resources.getDimensionPixelSize(resourceId)    } else {        resources.getDimensionPixelSize(R.dimen.default_status_bar_height)    }}

非全屏应用不需处理,不会被挡住

还有一些LJ厂商,状态栏高度跟刘海高度不一样的,网上搜索解决方案吧。。。

Android 9.0标准模式

不使用刘海区域

        val cutout = getDisplayCutout()        if (cutout != null) {            val lp = window.attributes            lp.layoutInDisplayCutoutMode = WindowManager.LayoutParams.LAYOUT_IN_DISPLAY_CUTOUT_MODE_NEVER            window.attributes = lp        }

使用刘海区域,然后设置应用全屏,并小心处理布局

        val cutout = getDisplayCutout()        if (cutout != null) {            val lp = window.attributes            lp.layoutInDisplayCutoutMode = WindowManager.LayoutParams.LAYOUT_IN_DISPLAY_CUTOUT_MODE_SHORT_EDGES            window.attributes = lp        }

更多相关文章

  1. 【Android】获取屏幕分辨率和顶栏高度全屏和横屏
  2. Android9.0默认使用MTP模式
  3. Android 工具类的两种写法---单例模式与静态方法
  4. android觀察者模式三種實現方法
  5. Android中Task任务栈的四种模式
  6. 设计模式—建造者模式及实例(BuilderPattern)
  7. Android全屏模式,沉浸模式。粘性沉浸模式
  8. Android设计模式学习之单例模式
  9. Android获取系统顶部状态栏(Status Bar)和底部导航栏(Navigation

随机推荐

  1. android EditText 全面阐述
  2. How to decompile .dex file on Android
  3. android更新
  4. Android(安卓)Camera使用小结
  5. 解决 Android(安卓)SDK下载和更新失败“C
  6. Android引用资源(resources) vs 引用样式属
  7. android Log.isLoggable步骤的使用
  8. Android(安卓)创建全局变量和Context
  9. TabHost—多种实现
  10. 四大布局