Splash Screen (Java) - Android Studio
In this tutorial i'll show you how to create a splash screen for your android app using android studio. We need at least two activities one is splash screen and second is some other activity that will display after splash screen.
Step 1: Create a new project OR Open your project
Step 2: Create New Activity File>New>Activity>EmptyActivity
Step 3: Place an image in res>drawable folder
Step 4: Open manifest and add
android:theme="@style/Theme.AppCompat.Light.NoActionBar"in <activity android:name=".SplashActivity" ...>
Step 5: Code:
AndroidManifest.xml<?xml version="1.0" encoding="utf-8"?> <manifest xmlns:android="http://schemas.android.com/apk/res/android" package="com.blogspot.devofandroid.myapplication"> <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=".SplashActivity" android:theme="@style/Theme.AppCompat.Light.NoActionBar"> <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>
activity_splash.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:layout_width="match_parent" android:layout_height="match_parent" android:orientation="vertical" android:gravity="center" android:background="@color/colorPrimary" tools:context=".SplashActivity"> <ImageView android:src="@drawable/logo" android:layout_width="250dp" android:layout_height="250dp" /> <TextView android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="Loading..." android:textColor="#fff" android:textSize="30sp" android:textStyle="bold" /> </LinearLayout>
SplashActivity.java
package com.blogspot.devofandroid.myapplication; import android.content.Intent; import android.os.Handler; import android.support.v7.app.AppCompatActivity; import android.os.Bundle; import android.view.Window; import android.view.WindowManager; public class SplashActivity extends AppCompatActivity { @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); //Hiding Title bar of this activity screen */ getWindow().requestFeature(Window.FEATURE_NO_TITLE); //Making this activity, full screen */ getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN, WindowManager.LayoutParams.FLAG_FULLSCREEN); setContentView(R.layout.activity_splash); new Handler().postDelayed(new Runnable() { @Override public void run() { startActivity(new Intent(SplashActivity.this, MainActivity.class)); finish(); } }, 4000); } }
activity_main.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:layout_width="match_parent" android:layout_height="match_parent" android:orientation="vertical" android:gravity="center" tools:context=".MainActivity"> <TextView android:text="Welcome" android:textSize="30sp" android:layout_width="wrap_content" android:layout_height="wrap_content" /> </LinearLayout>
MainActivity.java
package com.blogspot.devofandroid.myapplication; import android.support.v7.app.ActionBar; 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); } }
Comments
Post a Comment