如果多个view同时设置了fitsSystemWindows,只有第一个会起作用
解决办法:
/**
* 使所有子view的FitWindowSystem属性生效
*
* @param parents 父容器
* @param childs 需要生效FitWindowSystem属性的子view
*/
public static void validChildsFitWindowSystemProperty(View parents, final View... childs) {
ViewCompat.setOnApplyWindowInsetsListener(parents, new OnApplyWindowInsetsListener() {
@Override
public WindowInsetsCompat onApplyWindowInsets(View v, WindowInsetsCompat insets) {
insets = ViewCompat.onApplyWindowInsets(v, insets);
if (insets.isConsumed()) {
//父类已经设置,子类不再需要设置FitWindowSystem
return insets;
}
boolean consumed = false;
for (View child : childs) {
ViewCompat.dispatchApplyWindowInsets(child, insets);
if (insets.isConsumed()) {
consumed = true;
}
}
return consumed ? insets.consumeSystemWindowInsets() : insets;
}
});
}
网友评论