- mongodb - 在 MongoDB mapreduce 中,如何展平值对象?
- javascript - 对象传播与 Object.assign
- html - 输入类型 ="submit"Vs 按钮标签它们可以互换吗?
- sql - 使用 MongoDB 而不是 MS SQL Server 的优缺点
我很难理解 fitsSystemWindows
的概念,因为它会根据 View 做不同的事情。根据官方文档,这是一个
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
时,窗口插图(状态栏、导航栏...)应用于 View 填充,根据上面引用的文档工作。这是代码的相关部分:
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;
}
在新的 Material 设计中,新的类大量使用了这个标志,这就是困惑的地方。在许多来源中,fitsSystemWindows
被提及为设置为将 View 放置在系统栏后面的标志。见 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 并不能解决问题,因为默认实现会执行最初记录的操作。您必须覆盖它并添加与其他提到的类相同的标志。我错过了什么吗?
最佳答案
System windows are the parts of the screen where the system is drawing either non-interactive (in the case of the status bar) or interactive (in the case of the navigation bar) content.
Most of the time, your app won’t need to draw under the status bar or the navigation bar, but if you do: you need to make sure interactive elements (like buttons) aren’t hidden underneath them. That’s what the default behavior of the android:fitsSystemWindows=“true” attribute gives you: it sets the padding of the View to ensure the contents don’t overlay the system windows.
https://medium.com/google-developers/why-would-i-want-to-fitssystemwindows-4e26d9ce1eec
关于android - fitSystemWindows 到底是做什么的?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/31761046/
我有一个 View 需要锚定到屏幕底部。在全屏模式下,它需要位于最底部,但在临时非全屏模式(用户点击)期间,它需要向上移动以免被系统栏隐藏。文档说设置 android:fitsSystemWindow
我的应用程序有一个 Activity ,为每个部分托管不同的 fragment 。我最近通过将 fitSystemWindows 设置为 true 使状态栏变得半透明,这已将其设置为应用程序的背景色。
我很难理解 fitsSystemWindows 的概念,因为它会根据 View 做不同的事情。根据官方文档,这是一个 Boolean internal attribute to adjust view
我需要图像显示在状态栏下方(状态栏必须是透明的,不知道怎么做)但我无法让它工作,我已经尝试了很多布局示例。 这是我的 xml 布局:
我正在使用一个在主要 Activity 中有 3 个选项卡的应用程序。第二个选项卡的 fragment 有一个带有标题的 NestedScrollView,应该适合系统窗口。选项卡 fragment
我有一个使用 fitSystemWindows 能够在导航栏和状态栏后面绘制背景的应用程序 - 不幸的是,SnackBar 似乎忽略了容器中的 fitSystemWindows=true。我将问题归结
我有一个绑定(bind)到 ViewPager 的 MotionLayout 过渡。 private val pageChangedListener = object : SimpleOnPageCh
我有一个透明的状态/导航栏,当我使用默认布局(顶部/左侧)放置一个撰写元素时,它被放置在状态栏下方。在 xml 中我使用 fitsSystemWindows要解决这个问题,我怎样才能在 jetpack
我无法让我的 ViewPager 页面尊重状态栏高度。 我的 ViewPager 有几个页面,其中一个页面上有一个图像需要放在半透明状态栏下。其余的页面只需要一个彩色状态栏,所以我的想法是在 frag
我正在尝试在状态栏后面绘制 View ,如下所示: 我尝试使用推荐的技术来产生这种效果,但我明白了: 从屏幕截图中可以清楚地看出,我的应用内容都没有被绘制在状态栏后面。 有趣的是,Nav Drawer
当使用来自新的 Android 4.4 KitKat API 的半透明状态栏和导航栏时,将 fitsSystemWindows="true" 和 clipToPadding="false" 设置为 L
我是一名优秀的程序员,十分优秀!