首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >onApplyWindowInsets(WindowInsets insets)没有被调用

onApplyWindowInsets(WindowInsets insets)没有被调用
EN

Stack Overflow用户
提问于 2019-04-03 05:10:14
回答 3查看 9.3K关注 0票数 4

我目前使用的是扩展约束布局的自定义视图,但它不会触发视图onApplyWindowInsets(WindowInsets insets)中覆盖的方法,也不确定丢失了什么。

代码语言:javascript
复制
  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)
  }


}
EN

回答 3

Stack Overflow用户

回答已采纳

发布于 2019-04-04 11:20:29

一旦嵌入式被消耗,在层次结构中传播停止。看起来更高的东西正在消耗可用的东西。见isConsumed() of WindowsInset

检查这些插口是否已完全消耗。 如果调用了适用的such *方法,从而将所有Insets设置为零,则insets被视为“消费”。这会影响嵌入在视图层次结构中的传播;尚未完全消耗的嵌入将继续传播到子视图。

票数 4
EN

Stack Overflow用户

发布于 2020-06-14 20:12:01

我发现,如果没有将android:windowTranslucentStatus属性设置为true,则不会调用onApplyWindowInsets。这是我在阅读this unanswered question时发现的。

styles.xml

代码语言:javascript
复制
<style name="ExampleTheme" parent="Theme.AppCompat.NoActionBar">
  <item name="android:windowTranslucentStatus">true</item>
</style>

我很想了解为什么会这样,如果有一种方法可以在不需要更改属性的情况下调用它。

票数 4
EN

Stack Overflow用户

发布于 2019-10-14 08:36:46

我认为如果您想要重置它的windowInsets回调状态,您应该更改sysUiVisibility参数以让fitsSystemWindows正常工作。因为fitsSystemWindows是消费windowInsets的关键。你可以从android源代码中学到更多,当然,你需要时间。

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/55487471

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档