我当前正在使用扩展约束布局的自定义 View ,但是我不确定在onApplyWindowInsets(WindowInsets insets) View 中不会触发此覆盖的方法,不确定会丢失什么。
class TestCustomView @JvmOverloads constructor(
context: Context,
attrs: AttributeSet? = null,
defStyleAttr: Int = 0
) : ConstraintLayout(context, attrs, defStyleAttr) {
init {
}
//This method one not get called
override fun onApplyWindowInsets(insets: WindowInsets): WindowInsets {
return super.onApplyWindowInsets(insets)
val statusBarHeight = insets.systemWindowInsetTop
}
override fun fitSystemWindows(insets: Rect): Boolean {
if (Build.VERSION.SDK_INT == Build.VERSION_CODES.KITKAT) {
// Intentionally do not modify the bottom inset. For some reason,
// if the bottom inset is modified, window resizing stops working.
insets.left = 0
insets.top = 0
insets.right = 0
}
return super.fitSystemWindows(insets)
}
}
最佳答案
一旦插图被消耗掉,向下传播就停止了。看起来更高的东西正在消耗可用的东西。请参见 WindowsInset 中的 isConsumed()
。