- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我正在努力理解 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 - fitsSystemWindows 到底是做什么的?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/58142870/
我正在努力理解 fitsSystemWindows 的概念,因为它根据 View 执行不同的操作。根据官方文档,这是一个 Boolean internal attribute to adjust vi
我想为我的工具栏设置 FitsSystemWindows = true 或/和更改通知栏颜色。但它不起作用。我想做什么:image 我的代码在这里:样式 @color/color
我的 Android 应用以以下布局开始: Activity 有一个状态栏的偏移量。 我想通过单击按钮在运行时删除此偏移量。通过单击按钮,我执行以下操作,但它不起作用,没有任何反应:
我有一个 ConstraintLayout,我想在其中包含 Collapsing Toolbar Layout。所以,我遵循了本教程:https://antonioleiva.com/collapsi
我的布局中有这个: ... 但是我的应用中没有paddingLeft 或paddingRight。当我删除 fitsSystemWindows 时,填充又回来了。为什么?如何保留 fits
我正在使用来自 ksoichiro 的安卓库 Android-ObservableScrollView。我将他的示例 Flexible Space 与 viewpager 一起使用,并对其进行了修改。
在我的主题中,我定义了以下规则来在状态栏后面绘制我的 View : @android:color/transparent true 并在Activity中(onCreate): getWindow.g
尝试创建一个带有半透明状态栏和工具栏的简单 View ,但无法让工具栏按我预期的方式运行。工具栏似乎将 fitsSystemWindows bool 属性用于它的内部项目(标题、溢出菜单),但不是用于
Android Studio 2.3 RC 1 我创建了一个使用透明状态栏的应用程序,该应用程序工作正常,因为状态栏是透明的。问题出在我的工具栏上,因为它似乎被推高了。我一直在尝试使用 fitsSys
我发现如果父布局包含 android:fitsSystemWindows="true",当发生与 View 相关的操作时,它会干扰我的 BottomSheets 定位。 特别是我遇到的那个: Text
我用 Android Studio 2.0 创建了一个新的应用程序,我想在 Toolbar 下方放置 Navigation Drawer。我知道 Material Design 规范说它应该位于 To
我无法让带有折叠工具栏和嵌套 ScrollView 的 CoordinatorLayout 正常工作。 在除 CoordinatorLayout 之外的任何其他对象上设置 fitssystemwind
设置 现状 有限制: 这是内容的实际高度: AppBar
在我的应用程序中,我有一项 Activity 。此 Activity 的主题是 L 之前的正常主题,但对于 L 及更高版本会被覆盖,其中: ... true @color/statusTrans ..
我正在尝试使用 fitsSystemWindows="true"获得半透明的导航栏。它在 kitkat 中运行良好,半透明的导航栏使用 android:clipToPadding="false"显示内
我试图在我的应用程序中显示状态栏完全透明的 Activity 。我将此添加到我的样式中: @android:color/transparent true true 但由于某种原因,我的所有 View
我在 Activity 中有一个 ListView,它带有这样的操作栏: Activity 主题有: true true 在 Kitkat 设备下,行为是我想要的:项目在底部和顶
我在 NavigationView 中有一个自定义 View 。问题是无论采用何种组合,fitsSystemWindows 都无法在 NavigationView 中工作。并且抽屉中的顶部项目始终位于
我创建了一个项目,但只有一项 Activity 。当然只有一个xml文件。 xml文件中有两个ImageView,一个在顶部,另一个在底部。我为每个 ImageView 设置了 android:fit
对于我正在开发的应用程序,我想在用户输入后重新加载 UI(基本上是在他们对其进行更改后将其完全重置)。我想尝试避免破坏/重新创建 Activity 并改用 setContentView() 因为它要快
我是一名优秀的程序员,十分优秀!