2023-06-28

Why splash screen is not working in Kotlin app?

I am trying to make a splash screen in XML file but it is not working in emulator and there is only white screen in app view.

Here is activity_splash_screen.xml file:

<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    xmlns:tools="http://schemas.android.com/tools"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    tools:context=".Activity_Splash_Screen"    android:background="@color/black"
    >

    <ImageView
        android:id="@+id/image1"
        android:layout_width="150dp"
        android:layout_height="150dp"

        android:layout_centerInParent="true"
        android:src="@drawable/anadol" />

</RelativeLayout>

Activity_Splash_Screen.kt file:

package com.example.heytaksi

import android.content.Intent
import androidx.appcompat.app.AppCompatActivity
import android.os.Bundle
import com.example.heytaksi.databinding.ActivitySplashScreenBinding
import java.util.zip.Inflater

class Activity_Splash_Screen : AppCompatActivity() {
    lateinit var binding: ActivitySplashScreenBinding
    override fun onCreate(savedInstanceState: Bundle?) {
        super.onCreate(savedInstanceState)
        binding=ActivitySplashScreenBinding.inflate(layoutInflater)
        val b=binding.root
        binding.image1.alpha=0f
        binding.image1.animate().setDuration(1500).alpha(1f).withEndAction {
            val intent=Intent(this,MainActivity::class.java)
            startActivity(intent)
            overridePendingTransition(android.R.anim.fade_in,android.R.anim.fade_out)
            finish()
        }

    }
}

AndroidManifext.xml file:

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

    <application
        android:allowBackup="true"
        android:dataExtractionRules="@xml/data_extraction_rules"
        android:fullBackupContent="@xml/backup_rules"
        android:icon="@mipmap/ic_launcher"
        android:label="@string/app_name"
        android:roundIcon="@mipmap/ic_launcher_round"
        android:supportsRtl="true"
        android:theme="@style/Theme.HeyTaksi"
        tools:targetApi="31">

        <activity
            android:name=".MusteriGiris"
            android:exported="false" />
        <activity
            android:name=".Activity_Splash_Screen"
            android:exported="true"
            >
            <intent-filter>
                <action android:name="android.intent.action.MAIN" />

                <category android:name="android.intent.category.LAUNCHER" />
            </intent-filter>

        </activity>
        <activity
            android:name=".MainActivity"
            android:exported="false">

        </activity>
    </application>

</manifest>

The expectation was seeing the picture for a while before opening of application's main screen but it is staying in a white screen.



No comments:

Post a Comment