我目前使用的是扩展约束布局的自定义视图,但它不会触发视图onApplyWindowInsets(WindowInsets insets)中覆盖的方法,也不确定丢失了什么。
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)
}
}发布于 2019-04-04 11:20:29
一旦嵌入式被消耗,在层次结构中传播停止。看起来更高的东西正在消耗可用的东西。见isConsumed() of WindowsInset。
检查这些插口是否已完全消耗。 如果调用了适用的such *方法,从而将所有Insets设置为零,则insets被视为“消费”。这会影响嵌入在视图层次结构中的传播;尚未完全消耗的嵌入将继续传播到子视图。
发布于 2020-06-14 20:12:01
我发现,如果没有将android:windowTranslucentStatus属性设置为true,则不会调用onApplyWindowInsets。这是我在阅读this unanswered question时发现的。
在styles.xml中
<style name="ExampleTheme" parent="Theme.AppCompat.NoActionBar">
<item name="android:windowTranslucentStatus">true</item>
</style>我很想了解为什么会这样,如果有一种方法可以在不需要更改属性的情况下调用它。
发布于 2019-10-14 08:36:46
我认为如果您想要重置它的windowInsets回调状态,您应该更改sysUiVisibility参数以让fitsSystemWindows正常工作。因为fitsSystemWindows是消费windowInsets的关键。你可以从android源代码中学到更多,当然,你需要时间。
https://stackoverflow.com/questions/55487471
复制相似问题