info@thistimebd.com

Thursday 21st of November 07:01:04pm

splash screen android app source code

mainActivity.java

---------------------

package com.sam.web.splashscreen;


import android.support.v7.app.AppCompatActivity;

import android.os.Bundle;


public class MainActivity extends AppCompatActivity {


    @Override

    protected void onCreate(Bundle savedInstanceState) {

        super.onCreate(savedInstanceState);

        setContentView(R.layout.activity_main);

    }

}

=================================================================================================

activity_main.xml

-----------------


<?xml version="1.0" encoding="utf-8"?>

<android.support.constraint.ConstraintLayout 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="com.sam.web.splashscreen.MainActivity">


    <TextView

        android:layout_width="wrap_content"

        android:layout_height="wrap_content"

        android:text="Hello World!"

        app:layout_constraintBottom_toBottomOf="parent"

        app:layout_constraintLeft_toLeftOf="parent"

        app:layout_constraintRight_toRightOf="parent"

        app:layout_constraintTop_toTopOf="parent" />


</android.support.constraint.ConstraintLayout>

===================================================================================================

styles.xml

----------


<resources>


    <!-- Base application theme. -->

    <style name="AppTheme" parent="Theme.AppCompat.Light.NoActionBar">

        <!-- Customize your theme here. -->

        <item name="colorPrimary">@color/colorPrimary</item>

        <item name="colorPrimaryDark">@color/colorPrimaryDark</item>

        <item name="colorAccent">@color/colorAccent</item>

    </style>


</resources>

==================================================================================================

SplashScreen.java

=================


package com.sam.web.splashscreen;


import android.content.Intent;

import android.support.v7.app.AppCompatActivity;

import android.os.Bundle;

import android.view.Window;

import android.view.WindowManager;

import android.widget.ProgressBar;


public class SplashScreen extends AppCompatActivity {

    private ProgressBar progressBar;

    private int progress;


    @Override

    protected void onCreate(Bundle savedInstanceState) {

        super.onCreate(savedInstanceState);

        requestWindowFeature(Window.FEATURE_NO_TITLE);

        getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN,WindowManager.LayoutParams.FLAG_FULLSCREEN);

        setContentView(R.layout.activity_splash_screen);


        progressBar=(ProgressBar) findViewById(R.id.progressBarId);


        Thread thread=new Thread(new Runnable() {

            @Override

            public void run() {

                doWork();

                startApp();

            }

        });

        thread.start();

    }

    public void doWork(){

        for(progress=20; progress<=100; progress=progress+20){


            try {

                Thread.sleep(1000);

                progressBar.setProgress(progress);

            } catch (InterruptedException e) {

                e.printStackTrace();

            }



        }


    }

    public void startApp(){



        Intent intent=new Intent(SplashScreen.this,MainActivity.class);

        startActivity(intent);

        finish();

    }

}

===================================================================================

activity_splash_screen.xml

==========================


<?xml version="1.0" encoding="utf-8"?>

<LinearLayout 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:background="@drawable/background"

    android:layout_width="match_parent"

    android:layout_height="match_parent"

    android:gravity="bottom|center"

    tools:context="com.sam.web.splashscreen.SplashScreen">

    

    <ProgressBar

        android:progressBackgroundTint="#f9f9f9"

        android:progressTint="#02b3b9"

        android:id="@+id/progressBarId"

        android:layout_margin="80dp"

        android:layout_width="match_parent"

        android:layout_height="wrap_content"

        style="@android:style/Widget.ProgressBar.Horizontal"

        />


</LinearLayout>

===================================================================================


AndroidManifest.xml

======================


<?xml version="1.0" encoding="utf-8"?>

<manifest xmlns:android="http://schemas.android.com/apk/res/android"

    package="com.sam.web.splashscreen">


    <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/AppTheme">

        <activity android:name=".SplashScreen">

            <intent-filter>

                <action android:name="android.intent.action.MAIN" />


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

            </intent-filter>

        </activity>

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

    </application>


</manifest>