Monday, 30 May 2016

Android Splash Screen in Androiod Studio


Most Popular App such as Facebook, Skype, Twitter etc use splash screen before application launch. Splash Screen is very important in my app. Splash screen show brand of your company. So Start
How to Implement Splash Screen in Android studio
1) Firstly Create New Project
2) Write the name of the project 
3) Click next and select minimum sdk  and next and finish.

Firstly  Click App ---------- New Activity-----------Blank activity.
2) Write the name of your activity e.g welcome
3) Write the activity Name e.g. welcome_screen and click select launcher see this image i show you
and Click Finish. 


4) Click App--------res-------Click drawable and paste any image of size 800x1280 in drawable folder 

Now Open content_welcome.xml Your content_welcome these coding show
Delete all coding and add these lines in content_welcome
These lines addded your correct content_welcome.xml file is this


<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical" android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="@drawable/a">
</LinearLayout>
Note:- a is image name you can change any name but it is necessary same name write in  content_welcome.xml

 Then go to welcome.java
package com.karantips.splash;

import android.content.Intent;
import android.os.Bundle;
import android.support.design.widget.FloatingActionButton;
import android.support.design.widget.Snackbar;
import android.support.v7.app.AppCompatActivity;
import android.support.v7.widget.Toolbar;
import android.view.View;

public class Welcome extends AppCompatActivity {

    @Override    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.welcome_screen);
         Thread timerThread = new Thread(){
            public void run(){
                try{
                    sleep(5000);
                }catch(InterruptedException e){
                    e.printStackTrace();
                }finally{
                    Intent intent = new Intent(SplashScreen.this,MainActivity.class);
                    startActivity(intent);
                }
            }
        };
        timerThread.start();
    }

    @Override    protected void onPause() {
        // TODO Auto-generated method stub        super.onPause();
        finish();
    }

}







6) Now Open Android Manifest.xml and add these coding
 

<?xml version="1.0" encoding="utf-8"?>
  <manifest xmlns:android="http://schemas.android.com/apk/res/android"
    package="com.karantips.splash" >
    <application
    android:allowBackup="true"
    android:icon="@mipmap/ic_launcher"
    android:label="@string/app_name"
     android:supportsRtl="true"
     android:theme="@style/AppTheme" >
     <activity
      android:name=".MainActivity"
       android:label="@string/app_name"
        android:theme="@style/AppTheme.NoActionBar" >
        <intent-filter>

          <action android:name="android.intent.action.MAIN" />
         <category android:name="android.intent.category.DEFAULT" />
          </intent-filter>
       </activity>
       <activity
           android:name=".user"
            android:label="@string/title_activity_user"
            android:theme="@style/AppTheme.NoActionBar" >
            <intent-filter>
            <action android:name="android.intent.action.MAIN" />
           <category android:name="android.intent.category.LAUNCHER" />
           </intent-filter>
       </activity>
    </application>
  </manifest>



 Your project is complete see this output
 You Like my post Please share with friends
 

No comments:

Post a Comment