【问题标题】:Android splash activity displays behind system barsAndroid 启动画面显示在系统栏后面
【发布时间】:2018-08-14 06:23:54
【问题描述】:

我正在使用主题从可绘制对象中制作启动画面。但是,启动画面的可绘制对象显示在系统栏后面,如下所示。

这是我的可绘制初始屏幕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
    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>

我已经尝试在启动主题中将fitsSystemWindows 设置为true,而我的启动活动没有布局文件可以将fitsSystemWindows 设置为true。

我怎样才能让我的启动画面不显示在系统栏后面?

【问题讨论】:

  • 与其让它那样显示,为什么要让它全屏显示呢?

标签: android android-studio splash-screen


【解决方案1】:

找到解决方案:

在启动主题中,更改

<item name="android:windowBackground">@drawable/splash_screen</item>

<item name="android:background">@drawable/splash_screen</item>

现在可绘制的启动画面不会在系统栏后面绘制

来源:https://forums.xamarin.com/discussion/119638/splash-screen-using-android-windowbackground-does-goes-behind-statusbar

【讨论】:

    【解决方案2】:

    如果您不想花更多时间调试此问题,请使用 android:paddingTop="20dp" 进行简单快速的修复

    【讨论】:

      【解决方案3】:

      这将使您的启动画面进入全屏模式。只需将此添加到您的 onCreate()onCreateView()

       getWindow().getDecorView().setSystemUiVisibility(
                  View.SYSTEM_UI_FLAG_HIDE_NAVIGATION
                          | View.SYSTEM_UI_FLAG_FULLSCREEN);
      

      【讨论】:

        【解决方案4】:

        将此添加到您的onCreate() setContentView() 之前

        requestWindowFeature(Window.FEATURE_NO_TITLE);
        getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN,WindowManager.LayoutParams.FLAG_FULLSCREEN);
        

        这将使您的splash screen fullscreen

        【讨论】:

        • 不,不会。你会得到这个错误android.util.AndroidRuntimeException: requestFeature() must be called before adding content
        • 我通过先创建setContentView() 然后是使页面全屏的代码来做到这一点,我没有遇到错误
        【解决方案5】:

        在您的 Splash 主题中添加此代码:

        <item name="windowActionBar">false</item>
        <item name="windowNoTitle">true</item>
        

        【讨论】:

          【解决方案6】:

          如果您想删除状态栏,请在 setContentView(layout) 之前在 onCreateView 方法中使用它

          getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN,
          WindowManager.LayoutParams.FLAG_FULLSCREEN);
          

          或在您的 XML 设计中的父布局上设置 paddingTop ="20dp"

          android:paddingTop="20dp"
          

          【讨论】:

            【解决方案7】:

            你可以使用:

            android:layout_alignParentBottom="true"
            

            【讨论】:

              【解决方案8】:

              添加此样式

              <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>
              

              【讨论】:

                【解决方案9】:

                在你的 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

                【讨论】:

                  猜你喜欢
                  • 2023-03-26
                  • 1970-01-01
                  • 1970-01-01
                  • 1970-01-01
                  • 1970-01-01
                  • 2022-06-13
                  • 2017-12-28
                  • 2015-10-07
                  相关资源
                  最近更新 更多