//全屏对话框,兼容刘海屏
open class FullDialog2(context: Context): Dialog(context) {
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
val win = this.window!!
win.setBackgroundDrawable(ColorDrawable(Color.TRANSPARENT))
val lp = win.attributes
lp.width = WindowManager.LayoutParams.MATCH_PARENT
lp.height = WindowManager.LayoutParams.MATCH_PARENT
lp.gravity = Gravity.CENTER
//兼容刘海屏
if (Build.VERSION.SDK_INT >= 28) {
lp.layoutInDisplayCutoutMode = WindowManager.LayoutParams.LAYOUT_IN_DISPLAY_CUTOUT_MODE_SHORT_EDGES
}
win.attributes = lp
win.addFlags(WindowManager.LayoutParams.FLAG_DRAWS_SYSTEM_BAR_BACKGROUNDS)
val options = View.SYSTEM_UI_FLAG_LAYOUT_STABLE or View.SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN
win.decorView.systemUiVisibility = options
}
}
|