你好StackOverflowers。
我有这样的布局:
<androidx.drawerlayout.widget.DrawerLayout
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:id="@+id/drawerLayout"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="@drawable/background"
android:fitsSystemWindows="true"
tools:context=".MainActivity">
<androidx.constraintlayout.widget.ConstraintLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
>
......
>
它看起来像这样:
我只是将原色alpha设置为00,状态栏没有颜色。我喜欢的是它全屏显示在状态栏下。
我进行了另一个活动,但是它是一个ConstraintLayout,而不是上面的情况那样的DrawerLayout。我还设置了android:fitsSystemWindows =“ true”。但它不会全屏显示。
代码如下:
<androidx.constraintlayout.widget.ConstraintLayout
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:id="@+id/splashScreenLayout"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:fitsSystemWindows="true"
tools:context=".SplashScreen">
<ImageView>
.......
<>
我也可以使用DrawerLayout达到此效果,但是在该活动中不需要抽屉。 有没有更专业的方法?
答案 0 :(得分:0)
尝试在onCreate活动中使用它
if (Build.VERSION.SDK_INT < 16) {
window.setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN,
WindowManager.LayoutParams.FLAG_FULLSCREEN)
}
setContentView(R.layout.activity_main)
答案 1 :(得分:0)
我找到了答案。 我必须设置android:fitsSystemWindows =“ false”,并将此函数添加到may活动中,并在创建时调用它:
private fun showSystemUI() {
window.decorView.systemUiVisibility = (View.SYSTEM_UI_FLAG_LAYOUT_STABLE
or View.SYSTEM_UI_FLAG_LAYOUT_HIDE_NAVIGATION
or View.SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN)
}
即使我活动中的图像视图也位于状态栏下方。这正是我想要的。