我很难理解,AccuracySystemWindows的概念取决于视图它做不同的事情。根据官方文件,它是一个
Boolean internal attribute to adjust view layout based on system windows such as the status bar. If true, adjusts the padding of this view to leave space for the system windows.
现在,检查View.java类我可以看到,当设置为true时,窗口插入(状态栏,导航栏…)应用于视图paddings,它根据上面引用的文档工作。这是代码的相关部分:
private boolean fitSystemWindowsInt(Rect insets) {
if ((mViewFlags & FITS_SYSTEM_WINDOWS) == FITS_SYSTEM_WINDOWS) {
mUserPaddingStart = UNDEFINED_PADDING;
mUserPaddingEnd = UNDEFINED_PADDING;
Rect localInsets = sThreadLocal.get();
if (localInsets == null) {
localInsets = new Rect();
sThreadLocal.set(localInsets);
}
boolean res = computeFitSystemWindows(insets, localInsets);
mUserPaddingLeftInitial = localInsets.left;
mUserPaddingRightInitial = localInsets.right;
internalSetPadding(localInsets.left, localInsets.top,
localInsets.right, localInsets.bottom);
return res;
}
return false;
}
有了新的材料设计,有新的类,广泛使用这个标志,这是混乱的地方。在许多来源中,系统Windows被称为设置为将视图放置在系统栏后面的标志。见here。
ViewCompat.java中的setFitsSystemWindows文档说:
Sets whether or not this view should account for system screen decorations
such as the status bar and inset its content; that is, controlling whether
the default implementation of {@link View#fitSystemWindows(Rect)} will be
executed. See that method for more details.
根据这一点,fitsSystemWindows简单意味着函数fitsSystemWindows()将被执行?新的Material类似乎只是用于在状态栏下绘图。如果我们看看DrawerLayout.java的代码,我们可以看到:
if (ViewCompat.getFitsSystemWindows(this)) {
IMPL.configureApplyInsets(this);
mStatusBarBackground = IMPL.getDefaultStatusBarBackground(context);
}
… …
public static void configureApplyInsets(View drawerLayout) {
if (drawerLayout instanceof DrawerLayoutImpl) {
drawerLayout.setOnApplyWindowInsetsListener(new InsetsListener());
drawerLayout.setSystemUiVisibility(View.SYSTEM_UI_FLAG_LAYOUT_STABLE
| View.SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN);
}
}
我们在新的CoordinatorLayout或AppBarLayout中看到相同的模式。
这不工作与用于fitsSystemWindows的文档完全相反的方式吗?在最后的情况下,它意味着画在系统酒吧后面。
但是,如果你想要一个FrameLayout将自己绘制在状态栏后面,那么将fitsSystemWindows设置为true不会像默认实现那样做。你必须覆盖它,并添加与其他提到的类相同的标志。我缺少什么?