由于 Window 的 decorView 默认是设置有 10dp 的padding。需要获取到decorView后设置其padding为(0, 0, 0, 0) 即可。
override fun onStart() {
Logger.i(TAG, "onStart")
super.onStart()
setWindowParam()
}
/**
* 设置dialog的 window 参数
*/
private fun setWindowParam() {
val win = dialog?.window
win?.setBackgroundDrawable(ColorDrawable(Color.TRANSPARENT))
activity?.windowManager?.defaultDisplay?.getMetrics(DisplayMetrics())
win?.decorView?.setPadding(0, 0, 0, 0)
val params = win?.attributes ?: WindowManager.LayoutParams()
params?.dimAmount = 0f
params?.gravity = Gravity.BOTTOM
params?.width = MATCH_PARENT
params?.height = MATCH_PARENT
win?.attributes = params
}