Thursday 1 February 2018

Splash Screen in Android | How to make Splash screen without Action and Title bar

Its very easy to make splash screen without Action and Title bar in Android. for this we have to do following way.Please follow step by step:-

Step 1:- Add new project in  your android studio.
Step 2:- Make a new class and xml layouts name it as SplashScreen.class /splash_screen.xml.Make sure that your Splash Screen is Launcher screen. Code of Splash screen will be following.
 Splashscreen:-

public class SplashScreen extends AppCompatActivity {
    private static int SPLASH_TIME_OUT=3000;

    @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.splash_screen);
        new Handler().postDelayed(new Runnable() {
            @Override            public void run() {
                startActivity(new Intent(SplashScreen.this,MainActivity.class));
                finish();

            }
        },SPLASH_TIME_OUT);
    }
}
Step 3:- splash_screen.xml code will be following:-
<?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:layout_width="match_parent"    
android:layout_height="match_parent"    
android:orientation="vertical"    
android:gravity="center"    
android:background="#E1C61C"    
tools:context="com.example.supriyabharti.trading.SplashScreen">

    <TextView
android:layout_width="wrap_content"        
android:layout_height="wrap_content"        
android:text="MyTrading"        
android:fontFamily="cursive"        
android:gravity="center"        
android:textSize="50sp"        
android:textColor="#ffffff"        
android:textStyle="bold"/>

</LinearLayout>
Step 4:- Now to hide the status and header we have to make a style inside Style.xml file.Code will be following:-
Open styles.xml file (res -> values -> styles.xml) write following :-
<resources>
    <style name="AppTheme.NoActionBar">
        <item name="windowActionBar">false</item>
        <item name="windowNoTitle">true</item>
    </style>
</resources>
Step 4:- Now bit  changes in manifests file:- we have to give theme to the splash screen like following:-
<application>
<activity android:name=".SplashScreen"    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>
Step 4:- Make another activity with the name of MainActivity.java. After finishing from Splash screen app will be redirect to that activity.

No comments:

Post a Comment