Create a
splashscreen.xml
in
res/layout
folder path. Let's look at a simple design for a splash screen.
<linearlayout android:background="#FF7700"
android:layout_height="fill_parent"
android:layout_width="fill_parent"
android:orientation="horizontal"
xmlns:android="http://schemas.android.com/apk/res/android">
<textview android:gravity="center_vertical|center_horizontal"
android:id="@+id/txtHeader"
android:layout_gravity="center_horizontal"
android:layout_height="fill_parent"
android:layout_width="fill_parent" android:padding="10dp"
android:text="Splash Screen"
android:textcolor="#FFFFFF"
android:textsize="32sp"
android:textstyle="bold">
</textview>
</linearlayout>
Create a layout for the splash screen as you wish. Add the following code snippet to the
.java
class in
src
directory. Now run it on your created device.
public class SplashScreenActivity extends Activity {
@Override
protected void onCreate(Bundle savedInstanceState) {
// TODO Auto-generated method stub
super.onCreate(savedInstanceState);
// Create a full screen splash screen
requestWindowFeature(Window.FEATURE_NO_TITLE);
getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN,
WindowManager.LayoutParams.FLAG_FULLSCREEN);
setContentView(R.layout.splashscreen);
Handler handler = new Handler();
// run a thread after 4 seconds to start the home screen
handler.postDelayed(new Runnable() {
@Override
public void run() {
// make sure we close the splash screen so the user won't come
// back when it presses back key
finish();
// start the home screen
Intent intent = new Intent(SplashScreenActivity.this, MainActivity.class);
startActivity(intent);
}
}, 4000); // time in milliseconds (1 second = 1000 milliseconds) until
// the run() method will be called
}
}
Very nice post. I just stumbled upon your blog and wanted to say that I've really enjoyed browsing your blog posts. After all I’ll be subscribing to your rss feed and I hope you write again soon! apple service berlin
ReplyDelete