Posted by Shoaib at 7:54:00 pm
Read our previous post
MainActivity.java:
You don't need to change anything in MainActivity.
Splash.java:
package com.example.shoaibm.splashscreen; import android.app.Activity; import android.content.Intent; import android.support.v7.app.ActionBarActivity; import android.os.Bundle; import android.view.Menu; import android.view.MenuItem; import android.view.animation.Animation; import android.view.animation.AnimationUtils; import android.widget.ImageView; import java.util.logging.Handler; public class Splash extends Activity { @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_splash); Thread background = new Thread() { public void run() { try { sleep(3*1000); Intent i=new Intent(getBaseContext(),MainActivity.class); startActivity(i); finish(); } catch (Exception e) { } } }; background.start(); } }
Layout/activity_splash:
<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:paddingLeft="@dimen/activity_horizontal_margin" android:paddingRight="@dimen/activity_horizontal_margin" android:paddingTop="@dimen/activity_vertical_margin" android:paddingBottom="@dimen/activity_vertical_margin" tools:context="com.example.shoaibm.splashscreen.Splash"> <RelativeLayout android:id="@+id/loadingPanel" android:layout_width="match_parent" android:layout_height="match_parent" android:gravity="center" > <ProgressBar android:layout_width="wrap_content" android:layout_height="wrap_content" android:indeterminate="true" android:id="@+id/progressBar" android:layout_centerVertical="true" android:layout_centerHorizontal="true" /> <TextView android:layout_width="wrap_content" android:layout_height="wrap_content" android:textAppearance="?android:attr/textAppearanceLarge" android:text="Loading..." android:id="@+id/textView" android:layout_below="@+id/progressBar" android:layout_alignLeft="@+id/progressBar" android:layout_alignStart="@+id/progressBar" android:layout_marginTop="32dp" /> </RelativeLayout> </RelativeLayout>
No comments:
Post a Comment