kotlinandroid-custom-viewandroid-constraintlayout

onApplyWindowInsets(WindowInsets insets) not getting called


I am currently using a custom view that extends a Constraint layout but I it does not trigger this overridden method in the view onApplyWindowInsets(WindowInsets insets) not sure what went missing.

  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)
  }


}

Solution

  • Once the insets are consumed, propagation down the hierarchy stops. It looks like something higher up is consuming what's available. See isConsumed() of WindowsInset.

    Check if these insets have been fully consumed.

    Insets are considered "consumed" if the applicable consume* methods have been called such that all insets have been set to zero. This affects propagation of insets through the view hierarchy; insets that have not been fully consumed will continue to propagate down to child views.