【问题标题】:How can I remove white screen which appear before splash screen?如何删除在启动画面之前出现的白屏?
【发布时间】:2016-12-01 07:56:06
【问题描述】:

在打开 java 文件时,我首先会看到空白的白屏,然后它会出现在我的初始屏幕布局中。我有java文件:

new Handler().postDelayed(new Runnable() {
                @Override
                public void run() {
                    //Task 
                    finish();
                }
              }, ARG_SPLASH_TIME);

xml 文件中,我只需输入ImageView 并设置android:src 值。 在 manifest 文件中,我在启动器模式下打开 Splash 活动。

【问题讨论】:

    标签: android performance android-layout splash-screen


    【解决方案1】:

    终于得到我的答复Splash Screen in Right Way。我只是跟随。

    在 values->styles.xml 我创建了启动画面背景图片

    <style name="AppTheme.Splash" parent="AppTheme.NoActionBar">
        <item name="android:windowBackground">@drawable/splash</item>
    </style>
    

    对于低于 api 19,在 values-19->styles.xml 我使用了

    <style name="AppTheme.Splash" parent="AppTheme.NoActionBar">
        <item name="android:windowBackground">@drawable/splash</item>
        <item name="android:windowTranslucentStatus">true</item>
        <item name="android:windowTranslucentNavigation">true</item>
    </style>
    

    我从 SplashActivity 中删除了 setContentview(),并在 Manifest.xml 文件 android:theme="@style/AppTheme.Splash" 中添加了启动屏幕的样式

    【讨论】:

      【解决方案2】:

      好吧,白屏是 android 让系统感觉对用户更敏感的一种方式。用户点击应用,立即看到结果(应用)。

      那么我们如何改变这种行为呢?

      我们可以禁用此预览,正如@Piyush 所写:

      <item name="android:windowDisablePreview">true</item>
      

      但是这会让你的应用感觉迟缓,我的意思是,你暂时看不到任何东西,然后你会看到你的活动,而不是你期望发生的结果。

      更好的选择是在您的样式中使用活动。

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

      这将更改您的应用程序的默认背景,您可以为应用程序放置预加载器图像,例如带有您的徽标。

      两种情况下的用户都必须等待,但这感觉反应更快

      【讨论】:

        【解决方案3】:

        这是新发布的 Android Studio 的一个奇怪问题。第一次启动应用程序需要比平时更长的时间(看起来是白色的)。此问题仅在调试模式下发生,不会影响您发布的 APK。我也遇到了这个问题并找到了这个解决方案。

        设置/首选项→构建、执行、部署→即时运行并取消选中即时运行

        Instant run in Android Studio 2.0 (how to turn off)

        【讨论】:

          【解决方案4】:

          使用:

          <item name="android:windowDisablePreview">true</item>
          

          在您的应用主题的 style.xml 文件中。

          【讨论】:

          • 虽然它可以工作,但在延迟 2-3 秒后会显示飞溅,这有时会影响用户体验。
          【解决方案5】:

          你可以在你的启动活动中使用这种风格-

          <style name="YourTheme">
            <item name="android:windowBackground">@null</item>
          </style>
          

          【讨论】:

            【解决方案6】:

            有些答案现在不起作用,所以我更新了这个并确保它没问题。首先创建你的 xml 启动文件

            <?xml version="1.0" encoding="utf-8"?>
            <layer-list xmlns:android="http://schemas.android.com/apk/res/android">
                <item android:drawable="@color/black" />
            
                <item
                    android:width="@dimen/_145sdp"
                    android:height="@dimen/_30sdp"
                    android:drawable="@drawable/your_logo_here"
                    android:gravity="center" />
            </layer-list>
            

            在您的清单中:

            <activity
                        android:name=".ui.SplashActivity"
                        android:theme="@style/Theme.Splash">
                        <intent-filter>
                            <action android:name="android.intent.action.MAIN" />
                            <category android:name="android.intent.category.LAUNCHER" />
                        </intent-filter>
                    </activity>
            

            最后以你的风格:

            <style name="Theme.Splash" parent="@style/Theme.AppCompat.Light.NoActionBar">
                    <item name="android:windowBackground">@drawable/splash_screen</item>
            <!--        <item name="android:windowNoTitle">true</item>-->
            <!--        <item name="android:windowActionBar">false</item>-->
            <!--        <item name="android:windowFullscreen">true</item>-->
            <!--        <item name="android:windowContentOverlay">@null</item>-->
                </style>
            

            你不需要布局文件,没必要,去掉你类中的setContentView,像这样:

            class SplashActivity : AppCompatActivity() {
            
                override fun onCreate(savedInstanceState: Bundle?) {
                    super.onCreate(savedInstanceState)
                    setUpView()
                }
            
            
                private fun setUpView() {
                    Handler(Looper.getMainLooper()).postDelayed({
                        val intent = Intent(this, MainActivity::class.java)
                        //startActivity(intent)
                        // finishAffinity()
                    }, 2000)
            
                }
            }
            

            【讨论】:

              猜你喜欢
              • 2019-11-24
              • 2022-11-29
              • 2012-12-27
              • 2017-05-23
              • 1970-01-01
              • 1970-01-01
              • 2022-01-14
              • 1970-01-01
              • 2021-03-17
              相关资源
              最近更新 更多