Splash Screen之后的白色屏幕反应原生

时间:2017-04-21 02:56:45

标签: android react-native

[编辑]似乎是生成白色屏幕,因为MainActivity要加载很重,我设法首先使用本机启动画面解决,然后在本机被杀死基于下一个插件的js实现之后,我做了一些修改,以完美匹配两个闪屏 https://github.com/crazycodeboy/react-native-splash-screen

启动画面后的白屏反应原生。

enter image description here

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/gray"/>
    <item>
        <bitmap
            android:gravity="center"
            android:src="@mipmap/ic_launcher"/>
    </item>
</layer-list>

styles.xml

<resources>
    <!-- Base application theme. -->
    <style name="AppTheme" parent="Theme.AppCompat.Light.NoActionBar">
        <!-- Customize your theme here. -->
    </style>
    <style name="SplashTheme" parent="Theme.AppCompat.NoActionBar">
        <item name="android:windowBackground">@drawable/splash_screen</item>
    </style>
</resources>

AndroidManifiest.xml

<manifest xmlns:android="http://schemas.android.com/apk/res/android"
    package="com.appba"
    android:versionCode="1"
    android:versionName="1.0">

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

    <uses-sdk
        android:minSdkVersion="16"
        android:targetSdkVersion="22" />
    <application
      android:name=".MainApplication"
      android:allowBackup="true"
      android:label="@string/app_name"
      android:icon="@mipmap/ic_launcher"
      android:theme="@style/AppTheme">
      <activity
        android:name=".SplashActivity"
        android:label="@string/app_name"
        android:screenOrientation="portrait"
        android:theme="@style/SplashTheme">
        <intent-filter>
            <action android:name="android.intent.action.MAIN" />
            <category android:name="android.intent.category.LAUNCHER" />
        </intent-filter>
      </activity>
      <activity
        android:name=".MainActivity"
        android:label="@string/app_name"
        android:screenOrientation="portrait"
        android:configChanges="keyboard|keyboardHidden|orientation|screenSize"
        android:windowSoftInputMode="adjustResize">
      </activity>
      <activity android:name="com.facebook.react.devsupport.DevSettingsActivity" />
    </application>

</manifest>

SplashActivity.java

package com.appba;

import android.content.Intent;
import android.os.Bundle;
import android.support.v7.app.AppCompatActivity;

public class SplashActivity extends AppCompatActivity {

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);

        Intent intent = new Intent(this, MainActivity.class);
        startActivity(intent);
        finish();
    }
}

MainActivity.java

package com.appba;

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 String getMainComponentName() {
        return "appBa";
    }
}

知道如何避免空白屏幕吗?

我无法在Google上找到解决方案

我的启动基于以下方法。 https://www.bignerdranch.com/blog/splash-screens-the-right-way/

3 个答案:

答案 0 :(得分:1)

首先将LauncherActivity加载为MainActivity

MainActivity.java

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);

    Intent i = new Intent(this, Splash.class);
    startActivity(i);
}

Splash.java

private static int SPLASH_TIME_OUT = 5000;

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_splash);
    Handler handler = new Handler();
    handler.postDelayed(new Runnable() {
        @Override
        public void run() {
            finish();
        }
    }, SPLASH_TIME_OUT);
}

答案 1 :(得分:0)

如果您的活动显示来自数据库的数据一段时间冻结(白色屏幕)是正常的,如果这是您想要的,您应该在ProgressDialog内使用ProgressBarAsyncTask < / p>

答案 2 :(得分:0)

我知道解决这个问题的两种方法。 1.在java上编写代码,以便在Splash屏幕上产生更大的延迟。 2.添加android:theme =&#34; @ style / AppTheme&#34; in activity.MainActivity(在这种情况下,用户没有时间看到splash和MainActivity活动之间的区别)。