Android 启动画面 activity 显示在系统栏后面
Android splash activity displays behind system bars
我正在使用主题从可绘制对象制作启动画面。但是,启动画面的可绘制对象显示在系统栏后面,如下所示。
这是我的闪屏可绘制对象 splash_screen.xml
:
<?xml version="1.0" encoding="utf-8"?>
<layer-list xmlns:android="http://schemas.android.com/apk/res/android">
<item android:drawable="@color/slighty_red" />
<item>
<bitmap
android:src="@drawable/test_icon"
android:gravity="center_horizontal|bottom" />
</item>
</layer-list>
这是我的启动画面主题:
<style name="SplashTheme" parent="Theme.AppCompat.NoActionBar">
<item name="android:windowBackground">@drawable/splash_screen</item>
<item name="android:fitsSystemWindows">true</item> <!--Tried this but it doesn't work-->
</style>
然后我将这个主题应用于清单中的启动画面 activity:
<activity
android:name=".SplashActivity"
android:theme="@style/SplashTheme">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
我已经尝试在 splash 主题中将 fitsSystemWindows 设置为 true,而我的 splash activity 没有布局文件来将 fitsSystemWindows 设置为 true。
如何才能让我的启动画面不显示在系统栏后面?
如果您不想花更多时间调试此问题,可以使用 android:paddingTop="20dp"
进行简单快速的修复
在 setContentView()
之前将此添加到您的 onCreate()
requestWindowFeature(Window.FEATURE_NO_TITLE);
getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN,WindowManager.LayoutParams.FLAG_FULLSCREEN);
这将使您的 splash screen fullscreen
在您的 Splash 主题中添加此代码:
<item name="windowActionBar">false</item>
<item name="windowNoTitle">true</item>
如果您想删除状态栏,请在 onCreateView
方法 setContentView(layout)
之前使用此方法
getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN,
WindowManager.LayoutParams.FLAG_FULLSCREEN);
或在 XML 设计的父布局上设置 paddingTop ="20dp"
。
android:paddingTop="20dp"
这将使您的启动画面进入全屏模式。只需将此添加到您的 onCreate()
或 onCreateView()
.
getWindow().getDecorView().setSystemUiVisibility(
View.SYSTEM_UI_FLAG_HIDE_NAVIGATION
| View.SYSTEM_UI_FLAG_FULLSCREEN);
您可以使用:
android:layout_alignParentBottom="true"
添加此样式
<style name="SplashTheme" parent="Theme.AppCompat.NoActionBar">
<item name="android:windowBackground">@drawable/splash_screen</item>
<item name="windowActionBar">false</item>
<item name="windowNoTitle">true</item>
<item name="android:windowFullscreen">true</item> <!--use this to make the activity full screen-->
</style>
在你的 oncreate 中试试这个,
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
/** Hiding Title bar of this activity screen */
getWindow().requestFeature(Window.FEATURE_NO_TITLE);
/** Making this activity, full screen */
getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN, WindowManager.LayoutParams.FLAG_FULLSCREEN);
//setLayout
setContentView(R.layout.activity_splash);
}
并将主题设置为 Theme.AppCompact.NoActionBar
找到解决方案:
在启动主题中,更改
<item name="android:windowBackground">@drawable/splash_screen</item>
到
<item name="android:background">@drawable/splash_screen</item>
现在可绘制的闪屏不会在系统栏后面绘制
我正在使用主题从可绘制对象制作启动画面。但是,启动画面的可绘制对象显示在系统栏后面,如下所示。
这是我的闪屏可绘制对象 splash_screen.xml
:
<?xml version="1.0" encoding="utf-8"?>
<layer-list xmlns:android="http://schemas.android.com/apk/res/android">
<item android:drawable="@color/slighty_red" />
<item>
<bitmap
android:src="@drawable/test_icon"
android:gravity="center_horizontal|bottom" />
</item>
</layer-list>
这是我的启动画面主题:
<style name="SplashTheme" parent="Theme.AppCompat.NoActionBar">
<item name="android:windowBackground">@drawable/splash_screen</item>
<item name="android:fitsSystemWindows">true</item> <!--Tried this but it doesn't work-->
</style>
然后我将这个主题应用于清单中的启动画面 activity:
<activity
android:name=".SplashActivity"
android:theme="@style/SplashTheme">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
我已经尝试在 splash 主题中将 fitsSystemWindows 设置为 true,而我的 splash activity 没有布局文件来将 fitsSystemWindows 设置为 true。
如何才能让我的启动画面不显示在系统栏后面?
如果您不想花更多时间调试此问题,可以使用 android:paddingTop="20dp"
进行简单快速的修复
在 setContentView()
onCreate()
requestWindowFeature(Window.FEATURE_NO_TITLE);
getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN,WindowManager.LayoutParams.FLAG_FULLSCREEN);
这将使您的 splash screen fullscreen
在您的 Splash 主题中添加此代码:
<item name="windowActionBar">false</item>
<item name="windowNoTitle">true</item>
如果您想删除状态栏,请在 onCreateView
方法 setContentView(layout)
之前使用此方法
getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN,
WindowManager.LayoutParams.FLAG_FULLSCREEN);
或在 XML 设计的父布局上设置 paddingTop ="20dp"
。
android:paddingTop="20dp"
这将使您的启动画面进入全屏模式。只需将此添加到您的 onCreate()
或 onCreateView()
.
getWindow().getDecorView().setSystemUiVisibility(
View.SYSTEM_UI_FLAG_HIDE_NAVIGATION
| View.SYSTEM_UI_FLAG_FULLSCREEN);
您可以使用:
android:layout_alignParentBottom="true"
添加此样式
<style name="SplashTheme" parent="Theme.AppCompat.NoActionBar">
<item name="android:windowBackground">@drawable/splash_screen</item>
<item name="windowActionBar">false</item>
<item name="windowNoTitle">true</item>
<item name="android:windowFullscreen">true</item> <!--use this to make the activity full screen-->
</style>
在你的 oncreate 中试试这个,
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
/** Hiding Title bar of this activity screen */
getWindow().requestFeature(Window.FEATURE_NO_TITLE);
/** Making this activity, full screen */
getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN, WindowManager.LayoutParams.FLAG_FULLSCREEN);
//setLayout
setContentView(R.layout.activity_splash);
}
并将主题设置为 Theme.AppCompact.NoActionBar
找到解决方案:
在启动主题中,更改
<item name="android:windowBackground">@drawable/splash_screen</item>
到
<item name="android:background">@drawable/splash_screen</item>
现在可绘制的闪屏不会在系统栏后面绘制