刘海屏适配
16lz
2021-01-23
非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 }
更多相关文章
- 【Android】获取屏幕分辨率和顶栏高度全屏和横屏
- Android9.0默认使用MTP模式
- Android 工具类的两种写法---单例模式与静态方法
- android觀察者模式三種實現方法
- Android中Task任务栈的四种模式
- 设计模式—建造者模式及实例(BuilderPattern)
- Android全屏模式,沉浸模式。粘性沉浸模式
- Android设计模式学习之单例模式
- Android获取系统顶部状态栏(Status Bar)和底部导航栏(Navigation