在我的主题中,我定义了以下规则来在状态栏后面绘制我的 View :
<item name="android:statusBarColor">@android:color/transparent</item>
<item name="android:windowDrawsSystemBarBackgrounds">true</item>
并在Activity中(onCreate):
getWindow.getDecorView.setSystemUiVisibility(
View.SYSTEM_UI_FLAG_LAYOUT_STABLE |
View.SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN
)
然后,在我的 View 中,我使用了一个应该在状态栏后面绘制的 Barcodescanner,它正在工作。但是,当我将 android:fitsSystemWindows
应用于任何 subview 时,它们的位置不会得到调整。不过,当我将它应用于根元素时,它就起作用了。
<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>
最佳答案
使用 CoordinatorLayout 作为 View 的根,它对我有用。
<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">
关于android:fitsSystemWindows 不工作,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/28205473/