在主题中,我定义了以下规则以在状态栏后面绘制我的视图:
<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 im中,使用应该在状态栏后面绘制的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>
我的问题很可能与多重/嵌套fitsSystemWindows
属性有关,后来我发现它不起作用。我通过将属性应用于一个视图来解决我的问题,然后通过将填充内容复制到需要它们的其他视图ViewTreeObserver.OnGlobalLayoutListener
。那是一个丑陋的骇客,但目前已经可以完成。
本文收集自互联网,转载请注明来源。
如有侵权,请联系 [email protected] 删除。
我来说两句