Splash Screen in android
Now I am going to explain, how to start your app with splash screen.
1. Create a new project in the Eclipse IDE from File ⇒ Android Application Project and fill all required details. I named my main activity as MainActivity.java
In MainActivity.java
1. Create a new project in the Eclipse IDE from File ⇒ Android Application Project and fill all required details. I named my main activity as MainActivity.java
In MainActivity.java
package com.androidtutorialpoint;
import android.os.Bundle;
import android.os.Handler;
import android.app.Activity;
import android.content.Intent;
public class MainActivity extends Activity {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
int secondsDelayed = 1;
new Handler().postDelayed(new Runnable() {
public void run() {
startActivity(new Intent(MainActivity.this, HomePage.class));
finish();
}
}, secondsDelayed * 3000);
}
}
2. In order to create an View, we need xml layout files.Open your activity_main.xml
In activity_main.xml
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:paddingBottom="@dimen/activity_vertical_margin"
android:paddingLeft="@dimen/activity_horizontal_margin"
android:paddingRight="@dimen/activity_horizontal_margin"
android:paddingTop="@dimen/activity_vertical_margin"
tools:context=".MainActivity"
android:background="@drawable/sachintendulkar">
</RelativeLayout>
3. Create a new class in the Eclipse IDE from File ⇒ Class and fill all required details. I named this activity as HomePage.javaIn HomePage.java
package com.androidtutorialpoint;
import android.app.Activity;
import android.os.Bundle;
public class HomePage extends Activity {
@Override
protected void onCreate(Bundle savedInstanceState) {
// TODO Auto-generated method stub
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
}
}
4.Create xml file for your HomePage.java, i named it as main.xml,In main.xml
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical" >
<TextView
android:id="@+id/textView1"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="Welcome"
android:textSize="30dp" />
</LinearLayout>
Finally add HomePage.java in manifest as
<activity android:name="com.androidtutorialpoint.HomePage"/>The output Screen will be
Download source code here



0 comments: