Wednesday, 28 October 2015

Android Splash Screen

Many popular Android Apps such as Skype, Facebook, Adobe Reader, 500px, Dropbox etc.,  uses splash screen to display their logo. Most Android Apps uses Android Splash Screen before launching application Activity. Android splash screen is used to display a logo or brand for an app. In this article we are going to discuss about implementing an Android Splash Screen in a simple manner
activity_main.xml
-----------------------------
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout
   
xmlns:android="http://schemas.android.com/apk/res/android"
   
xmlns:tools="http://schemas.android.com/tools"
   
xmlns:app="http://schemas.android.com/apk/res-auto"
   
android:layout_width="match_parent"
   
android:layout_height="match_parent"
   
app:layout_behavior="@string/appbar_scrolling_view_behavior"
   
tools:showIn="@layout/activity_main"
   
tools:context=".MainActivity"
   
android:orientation="vertical"
   
android:background="@mipmap/logo">

</
LinearLayout>

MainActivity.Java
--------------------------------
package com.android.anil.splashscreen;

import android.content.Intent;
import android.os.Bundle;
import android.support.v7.app.AppCompatActivity;
import android.support.v7.widget.Toolbar;

public class MainActivity extends AppCompatActivity {
   
@Override
   
protected void onCreate(Bundle savedInstanceState) {
       
super.onCreate(savedInstanceState);
        setContentView(R.layout.
activity_main);
        Toolbar toolbar = (Toolbar) findViewById(R.id.
toolbar);
        setSupportActionBar(toolbar);
        Thread splashthread=
new Thread(){
           
@Override
           
public void run() {
               
super.run();
               
try {
                    sleep(
5000);
                }
catch (InterruptedException e) {
                    e.printStackTrace();
                }
finally {
                    finish();
                    startActivity(
new Intent(getApplicationContext(),HomeActivity.class));
                }
            }
        };
        splashthread.start();
    }
}

Output is:
----------------------


No comments:

Post a Comment