Background image display during Android startup

Source: Internet
Author: User

Transferred from: http://blog.csdn.net/zhangzhikaixinya/article/details/17001321

Most Android apps will have a background image set up during startup, until the app is loaded and the picture disappears. Therefore, it is also one of the basic skills for Android apps. This process is not difficult to achieve.

In total, you need the following: 2 activity, one background, 2 XML configuration files, string.xml,androidmanifest write configuration information.

1 Prepare a picture of the background image, named load, choose your own picture format. Put it under the drawable directory.

2 Creating the Load page Loadactivity.java and related layout files Load.xml

Loadactivity.java

[Java]View Plaincopy
  1. Package com.timothy.load;
  2. Import android.app.Activity;
  3. Import Android.os.Bundle;
  4. Import android.content.Intent;
  5. Import Android.graphics.PixelFormat;
  6. Import Android.os.Handler;
  7. Import Android.view.WindowManager;
  8. Public class Loadactivity extends Activity {
  9. //time for picture display
  10. private static final int load_display_time = 1500;
  11. /** Called when the activity is first created. * /
  12. @Override
  13. public void OnCreate (Bundle savedinstancestate) {
  14. super.oncreate (savedinstancestate);
  15. GetWindow (). SetFormat (pixelformat.rgba_8888);
  16. GetWindow (). Addflags (WindowManager.LayoutParams.FLAG_DITHER);
  17. Setcontentview (R.layout.load);
  18. new Handler (). postdelayed (new Runnable () {
  19. public Void Run () {
  20. //go to main activity, and finish load activity
  21. Intent mainintent = new Intent (loadactivity. This, mainactivity.  class);
  22. Loadactivity.  this.startactivity (mainintent);
  23. Loadactivity.  This.finish ();
  24. }
  25. }, Load_display_time);
  26. }
  27. }


Load.xml

[HTML]View Plaincopy
  1. <? XML version= "1.0" encoding="Utf-8"?>
  2. <linearlayout xmlns:android="http://schemas.android.com/apk/res/android"
  3. android:orientation="vertical"
  4. android:gravity="Center|center"
  5. android:layout_width="fill_parent"
  6. android:layout_height="fill_parent"
  7. android:background="@drawable/load">
  8. </linearlayout>


3 Creating a master page Mainactivity.java and related layout files Main.xml

Mainactivity.java

[Java]View Plaincopy
  1. Package com.timothy.load;
  2. Import android.app.Activity;
  3. Import Android.os.Bundle;
  4. Public class Mainactivity extends Activity {
  5. /** Called when the activity is first created. * /
  6. @Override
  7. public void OnCreate (Bundle savedinstancestate) {
  8. super.oncreate (savedinstancestate);
  9. Setcontentview (R.layout.main);
  10. }
  11. }


Main.xml

[HTML]View Plaincopy
  1. <? XML version= "1.0" encoding="Utf-8"?>
  2. <linearlayout xmlns:android="http://schemas.android.com/apk/res/android"
  3. android:orientation="vertical"
  4. android:layout_width="fill_parent"
  5. android:layout_height="fill_parent"
  6. >
  7. <TextView
  8. android:layout_width="fill_parent"
  9. android:layout_height="wrap_content"
  10. android:text="@string/hello"
  11. />
  12. </linearlayout>


4 Configuring Strings.xml

[HTML]View Plaincopy
  1. <? XML version= "1.0" encoding="Utf-8"?>
  2. <resources>
  3. <string name="Hello">hello, this is a demo-to-picture before app start</string >
  4. <string name="app_name">loadpicturedemo</string>
  5. <style name= "MyTheme.NoTitleBar.CustomBackground" parent="@android: Theme.black" >
  6. <item name="Android:windowbackground"> @drawable/load</Item>
  7. <item name="Android:windownotitle">true</Item>
  8. <item name="Android:windowfullscreen">true</Item>
  9. <item name="Android:windowcontentoverlay"> @null</Item>
  10. </style>
  11. </Resources>


5 Configuring Androidmanifest.xml

[HTML]View Plaincopy
  1. <? XML version= "1.0" encoding="Utf-8"?>
  2. <manifest xmlns:android="http://schemas.android.com/apk/res/android"
  3. package="Com.timothy.load"
  4. android:versioncode="1"
  5. android:versionname="1.0">
  6. <uses-sdk android:minsdkversion="8" />
  7. <application android:icon="@drawable/icon" android:label="@string/app_name" >
  8. <activity android:name=". Loadactivity "
  9. android:configchanges="Orientation|keyboardhidden"
  10. android:theme="@style/mytheme.notitlebar.custombackground">
  11. <intent-filter>
  12. <action android:name="Android.intent.action.MAIN" />
  13. <category android:name="Android.intent.category.LAUNCHER" />
  14. </intent-filter>
  15. </Activity>
  16. <activity android:name=". Mainactivity ">
  17. </Activity>
  18. </Application>
  19. </manifest>


6 OK, compile and run

During the startup process:

Finish Startup:

Background image display during Android startup

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.