First, create a drawable with the following content, its name being background_splash:
<?xml version="1.0" encoding="utf-8"?>
<layer-list xmlns:android="http://schemas.android.com/apk/res/android">
<item android:drawable="@color/gray"/> <!--aqui pode ser qualquer coisa, até uma imagem-->
<item>
<bitmap
android:gravity="center"
android:src="@mipmap/ic_launcher"/>
</item>
</layer-list>
Done this, you will in your Styles.xml put this snippet of code:
<style name="Splash" parent="Theme.AppCompat.NoActionBar">
<item name="android:windowBackground">@drawable/background_splash</item>
</style>
Then, in your manifest, you will put the following, in the statement of your Activity, remembering that it has to be the Auncher and main project:
<activity
android:name=".SplashActivity"
android:theme="@style/Splash">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
Ai on Activity’s onCreate, you can do all the necessary processing. It doesn’t even need to have the setContentView statement():
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
//Aqui você faz todo e qualquer processamento necessário, depois inicializa sua MainActivity e finaliza a splash, pra tirar ela do back stack.
Intent intent = new Intent(this, MainActivity.class);
startActivity(intent);
finish();
}
Edit the question to post the code you used to create this Splash Activity. Java and XML.
– Rosário Pereira Fernandes