28 lines
894 B
Kotlin
28 lines
894 B
Kotlin
package com.gh.common.view
|
|
|
|
import android.content.Context
|
|
import android.os.Build
|
|
import android.util.AttributeSet
|
|
import android.widget.FrameLayout
|
|
|
|
class MaterializedFrameLayout @JvmOverloads constructor(context: Context, attrs: AttributeSet? = null)
|
|
: FrameLayout(context, attrs) {
|
|
|
|
/**
|
|
* 将 windowInsets 传递给子 view [https://medium.com/androiddevelopers/why-would-i-want-to-fitssystemwindows-4e26d9ce1eec#.raoa9t506]
|
|
*/
|
|
override fun onAttachedToWindow() {
|
|
super.onAttachedToWindow()
|
|
|
|
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
|
|
setOnApplyWindowInsetsListener { _, insets ->
|
|
val childCount = childCount
|
|
for (index in 0 until childCount) {
|
|
getChildAt(index).dispatchApplyWindowInsets(insets)
|
|
}
|
|
insets
|
|
}
|
|
}
|
|
}
|
|
|
|
} |