Skip to content

Instantly share code, notes, and snippets.

@webserveis
Created December 4, 2019 17:08
Show Gist options
  • Save webserveis/d7ec0264ae77b31269b2f380b7e70c67 to your computer and use it in GitHub Desktop.
Save webserveis/d7ec0264ae77b31269b2f380b7e70c67 to your computer and use it in GitHub Desktop.
Crear un splashscreen en kotlin Android

Splash Screen en Android

Crear una pantalla de bienvenida (splashscreen) para nuestras apps

Recursos

Icono de la palicación app\src\main\res\mipmap-xhdpi\ic_launcher.png Crear una fondo de pantalla de tamaño 720x1280 (xhdpi) Escoger un color de fondo, por ejemplo #465f7e Centrar el icono a la imágen y guardarla en app\src\main\res\drawable-xhdpi\splashscreen.png

Preparativos

En el archivo res\values\colors.xml añadir la entrada

    <color name="colorSplashScreen">#465f7e</color>

Crear el archivo bg_splashscreen.xml en app\src\main\res\drawable\

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

    <!-- The background color, preferably the same as your normal theme -->
    <item android:drawable="@color/colorSplashScreen"/>

    <item><!-- android:top="-48dp" -->
        <bitmap
            android:src="@drawable/splashscreen"
            android:gravity="center" />
    </item>
</layer-list>

En el archivo res\values\styles.xml añadir un nuevo estilo

    <style name="AppTheme.SplashScreen" parent="AppTheme">
        <item name="windowActionBar">false</item>
        <item name="windowNoTitle">true</item>
        <item name="android:windowFullscreen">true</item>
        <item name="android:windowTranslucentNavigation">true</item>
        <item name="android:windowEnterAnimation">@android:anim/fade_in</item>
        <item name="android:windowBackground">@drawable/bg_splash</item>
    </style>

Insertar una actividad en blanco y llamarla SplashScreenActivity

Asignar el tema AppTheme.SplashScreen en la actividad en el archivo AndroidManifest.xml

        <activity android:name=".SplashScreen"
            android:theme="@style/AppTheme.SplashScreen">
            >
            <intent-filter>
                <action android:name="android.intent.action.MAIN" />
                <category android:name="android.intent.category.LAUNCHER" />
            </intent-filter>
        </activity>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment