android:fitsSystemWindows无效

Tai*_*aig 20 android android-view

在我的主题中,我定义了以下规则来在状态栏后面绘制我的观点:

<item name="android:statusBarColor">@android:color/transparent</item>
<item name="android:windowDrawsSystemBarBackgrounds">true</item>
Run Code Online (Sandbox Code Playgroud)

并在Activity(onCreate)中:

getWindow.getDecorView.setSystemUiVisibility(
    View.SYSTEM_UI_FLAG_LAYOUT_STABLE |
    View.SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN
)
Run Code Online (Sandbox Code Playgroud)

然后,在我的View中使用Barcodescanner,它应该在状态栏后面绘制,这是有效的.但是,当我应用于android:fitsSystemWindows任何子视图时,他们不会调整其位置.但是,当我将它应用于根元素时,它正在工作.

<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
             android:layout_width="wrap_content"
             android:layout_height="wrap_content">

    <my.Scanner
        android:id="@+id/scanner"
        android:layout_width="match_parent"
        android:layout_height="match_parent" />

    <FrameLayout android:layout_width="match_parent"
                 android:layout_height="match_parent"
                 android:fitsSystemWindows="true"> <!-- Should receive a top padding, right? -->

        <View android:layout_width="50dp"
              android:layout_height="50dp"
              android:background="@color/red" />

    </FrameLayout>

</FrameLayout>
Run Code Online (Sandbox Code Playgroud)

截图

Ali*_*aca 20

使用CoordinatorLayout作为视图的根,它对我有用.

<android.support.design.widget.CoordinatorLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:fitsSystemWindows="true">
Run Code Online (Sandbox Code Playgroud)


Tai*_*aig 14

我的问题很可能与多个/嵌套fitsSystemWindows属性有关,这些属性不能像我后面发现的那样起作用.我通过将属性应用于一个视图解决了我的问题,然后通过一个视图将填充复制到需要它们的其他视图ViewTreeObserver.OnGlobalLayoutListener.这是一个丑陋的黑客,但现在它的工作.

  • 当我尝试在层次结构中的两个视图上使用fitsSystemWindows时,我也遇到了问题.当我将这两个视图放在一个容器中并为该容器设置fitsSystemWindows时,我解决了这个问题 (7认同)

Nin*_*nja 5

我在Android 4.4中遇到了同样的问题

我的问题是 <item name="android:windowTranslucentStatus">true</item>

和...有冲突<item name="android:fitsSystemWindows">true</item>

我的方法是删除 <item name="android:windowTranslucentStatus">true</item>