Splash screen are used in android apps in the beginning of app when the user open the app.they are used to give app a little time to load data from server at beginning for for loading app content and providing user better UI interface.
NOTE:keep the image in your drawable and then access it in your xml file.
NOTE:keep the image in your drawable and then access it in your xml file.
Manifest file
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.apkglobal.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=".MainActivity"> <intent-filter> <action android:name="android.intent.action.MAIN" /> <category android:name="android.intent.category.LAUNCHER" /> </intent-filter> </activity> </application> </manifest>
Java file
package com.splashscreen; import android.content.Intent; import android.os.Handler; import android.support.v7.app.AppCompatActivity; import android.os.Bundle; public class MainActivity extends AppCompatActivity { private static int splash_time_out=4000; @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); new Handler().postDelayed(new Runnable() { @Override public void run() { Intent intent=new Intent(MainActivity.this,HomeActivity.class); startActivity(intent); finish(); } },splash_time_out); } }
XML file<?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=".MainActivity"> <LinearLayoutandroid:layout_width="match_parent"android:layout_height="match_parent"android:background="#8BC34A"android:gravity="center"android:orientation="vertical"> <ImageViewandroid:id="@+id/logo"android:layout_width="200dp"android:layout_height="200dp"android:src="@drawable/sample" /> <TextViewandroid:layout_width="wrap_content"android:layout_height="wrap_content"android:text="Splash screen"android:textSize="50sp" /> </LinearLayout> </android.support.constraint.ConstraintLayout>
No comments:
Post a Comment