【问题标题】:How to reduce Splash Screen time如何减少启动画面时间
【发布时间】:2020-09-13 18:09:32
【问题描述】:

需要7-10秒,我想知道有没有办法减少时间。在我安装启动画面之前,主页会在 2-3 秒内加载完毕。我已经安装了react-native-splash-screen 包并使用@bam.tech/react-native-make 自动配置了android 文件。

如果您想知道的话,从未在真实设备上尝试过。

MainActivity.java

package com.myApp;

import android.os.Bundle;
import org.devio.rn.splashscreen.SplashScreen;
import com.facebook.react.ReactActivity;

public class MainActivity extends ReactActivity {

  /**
   * Returns the name of the main component registered from JavaScript. This is used to schedule
   * rendering of the component.
   */
  @Override
  protected void onCreate(Bundle savedInstanceState) {
      SplashScreen.show(this, R.style.SplashScreenTheme);
      super.onCreate(savedInstanceState);
  }

  @Override
  protected String getMainComponentName() {
    return "myApp";
  }
}

AndroidManifest.xml

<manifest xmlns:android="http://schemas.android.com/apk/res/android" package="com.myApp">

    <uses-permission android:name="android.permission.INTERNET" />

    <application
      android:name=".MainApplication"
      android:label="@string/app_name"
      android:icon="@mipmap/ic_launcher"
      android:allowBackup="false"
      android:theme="@style/AppTheme">
        <activity
          android:name=".MainActivity"
          android:label="@string/app_name"
          android:configChanges="keyboard|keyboardHidden|orientation|screenSize|uiMode"
          android:launchMode="singleTask"
          android:windowSoftInputMode="adjustResize">
          <intent-filter>
            <action android:name="android.intent.action.MAIN" />
            <category android:name="android.intent.category.LAUNCHER" />
          </intent-filter>
        </activity>
      <activity android:name="com.facebook.react.devsupport.DevSettingsActivity" />
    </application>

</manifest>

splashscreen.xml

<?xml version="1.0" encoding="utf-8"?>
<layer-list xmlns:android="http://schemas.android.com/apk/res/android">

    <item android:drawable="@color/splashprimary" />
    <item>
        <bitmap
                android:gravity="center"
                android:src="@drawable/splash_image" />
    </item>

</layer-list>

styles.xml

<resources>

    <style name="SplashScreenTheme" parent="SplashScreen_SplashTheme">
        <item name="colorPrimaryDark">@color/splashprimary</item>
        <item name="android:statusBarColor">@color/app_bg</item>
    </style>

    <!-- Base application theme. -->
    <style name="AppTheme" parent="Theme.AppCompat.Light.NoActionBar">
        <!-- Customize your theme here. -->
        <item name="android:textColor">#000000</item>

        <!-- Add the following line to set the default status bar color for all the app. -->
        <item name="android:statusBarColor">@color/app_bg</item>
        <!-- Add the following line to set the default status bar text color for all the app 
        to be a light color (false) or a dark color (true) -->
        <item name="android:windowLightStatusBar">false</item>
        <!-- Add the following line to set the default background color for all the app. -->
        <item name="android:windowBackground">@color/app_bg</item>
    </style>

</resources>

【问题讨论】:

  • 我通常使用活动和计时器创建自己的启动画面。从来不知道这件事。感谢您的信息!
  • @SandrinJoy,react-native-make 让它非常容易实现,你只需要一个 .png 的启动画面。也不要忘记在你的根文件中隐藏启动画面SplashScreen.hide()
  • 所以没有动画?嗯。那是一个沉闷的启动画面
  • 是的,它只将 .png 文件显示为启动画面。
  • 专业人士实际采用的是哪种方法?

标签: java android react-native react-native-android splash-screen


【解决方案1】:

尝试在 Style.xml 中添加它

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

这将删除开始时出现的白屏。

【讨论】:

  • 我试过了,但仍然需要至少 7 秒才能加载
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2014-02-03
  • 2018-04-12
  • 2013-08-29
  • 1970-01-01
  • 1970-01-01
  • 2021-12-21
相关资源
最近更新 更多