I need to make a splash screen for a java application, but even following the steps of the internet tutorials I can't get it to work well.
I would like the splash screen to be a green color, and then the application logo in the middle. The problem is that I only get the green background to appear, or if I change the order of the items in splash_screen.xml, the photo with a black background. In the .xml I get the following warning:
I have tried to put different sizes and types of images, and even the ic_launchers that come by default in @mipmap, but there is no way that it works. Let's see if someone can help me! Attached is the code I have so far. Thank you!
splash_screen.xml
<?xml version="1.0" encoding="utf-8"?>
<selector xmlns:android="http://schemas.android.com/apk/res/android">
<item android:drawable="@color/blue"/>
<item>
<bitmap
android:gravity="center"
android:src="@drawable/imagen"/>
</item>
</selector>
themes.xml
<resources xmlns:tools="http://schemas.android.com/tools">
<!-- Base application theme. -->
<style name="Theme.CookPad" parent="Theme.MaterialComponents.DayNight.DarkActionBar">
<!-- Primary brand color. -->
<item name="colorPrimary">@color/blue</item>
<item name="colorPrimaryVariant">@color/black</item>
<item name="colorOnPrimary">@color/white</item>
<!-- Secondary brand color. -->
<item name="colorSecondary">@color/teal_200</item>
<item name="colorSecondaryVariant">@color/teal_700</item>
<item name="colorOnSecondary">@color/black</item>
<!-- Status bar color. -->
<item name="android:statusBarColor" tools:targetApi="l">?attr/colorPrimaryVariant</item>
<!-- Customize your theme here. -->
</style>
<style name="SplashTheme" parent="Theme.CookPad">
<item name="android:windowBackground">@drawable/splash_screen</item>
</style>
</resources>
colors.xml
<?xml version="1.0" encoding="utf-8"?>
<resources>
<color name="purple_200">#FFBB86FC</color>
<color name="purple_500">#FF6200EE</color>
<color name="purple_700">#FF3700B3</color>
<color name="teal_200">#FF03DAC5</color>
<color name="teal_700">#FF018786</color>
<color name="black">#FF000000</color>
<color name="white">#FFFFFFFF</color>
<color name="blue">#9CDEB3</color>
</resources>
AndroidManifest.xml
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="edu.mondragon.cookpad">
<application
android:allowBackup="true"
android:icon="@mipmap/ic_launcher"
android:label="@string/app_name"
android:roundIcon="@mipmap/ic_launcher_round"
android:supportsRtl="true"
android:theme="@style/Theme.CookPad">
<activity
android:name=".Activity_Cocinero"
android:exported="false" />
<activity
android:name=".Activity_Camarero"
android:exported="false" />
<activity
android:name=".MainActivity"
android:theme="@style/SplashTheme"
android:exported="true">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
</application>
</manifest>
MainActivity onCreate function
@Override
protected void onCreate(Bundle savedInstanceState) {
try{
Thread.sleep(1000);
}catch(InterruptedException e){
}
setTheme(R.style.Theme_CookPad);
super.onCreate(savedInstanceState);
setContentView(R.layout.layout_main);
{
Example: splash_screen.xml
<item android:drawable="@color/blue"/>
<item>
<bitmap
android:gravity="center"
android:src="@drawable/imagen"/>
</item>
<?xml version="1.0" encoding="utf-8"?>
<selector xmlns:android="http://schemas.android.com/apk/res/android">
<item>
<bitmap
android:gravity="center"
android:src="@drawable/imagen"/>
</item>
<item android:drawable="@color/blue"/>
</selector>