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
- Package com.timothy.load;
- Import android.app.Activity;
- Import Android.os.Bundle;
- Import android.content.Intent;
- Import Android.graphics.PixelFormat;
- Import Android.os.Handler;
- Import Android.view.WindowManager;
- Public class Loadactivity extends Activity {
- //time for picture display
- private static final int load_display_time = 1500;
- /** Called when the activity is first created. * /
- @Override
- public void OnCreate (Bundle savedinstancestate) {
- super.oncreate (savedinstancestate);
- GetWindow (). SetFormat (pixelformat.rgba_8888);
- GetWindow (). Addflags (WindowManager.LayoutParams.FLAG_DITHER);
- Setcontentview (R.layout.load);
- new Handler (). postdelayed (new Runnable () {
- public Void Run () {
- //go to main activity, and finish load activity
- Intent mainintent = new Intent (loadactivity. This, mainactivity. class);
- Loadactivity. this.startactivity (mainintent);
- Loadactivity. This.finish ();
- }
- }, Load_display_time);
- }
- }
Load.xml
[HTML]View Plaincopy
- <? XML version= "1.0" encoding="Utf-8"?>
- <linearlayout xmlns:android="http://schemas.android.com/apk/res/android"
- android:orientation="vertical"
- android:gravity="Center|center"
- android:layout_width="fill_parent"
- android:layout_height="fill_parent"
- android:background="@drawable/load">
- </linearlayout>
3 Creating a master page Mainactivity.java and related layout files Main.xml
Mainactivity.java
[Java]View Plaincopy
- Package com.timothy.load;
- Import android.app.Activity;
- Import Android.os.Bundle;
- Public class Mainactivity extends Activity {
- /** Called when the activity is first created. * /
- @Override
- public void OnCreate (Bundle savedinstancestate) {
- super.oncreate (savedinstancestate);
- Setcontentview (R.layout.main);
- }
- }
Main.xml
[HTML]View Plaincopy
- <? XML version= "1.0" encoding="Utf-8"?>
- <linearlayout xmlns:android="http://schemas.android.com/apk/res/android"
- android:orientation="vertical"
- android:layout_width="fill_parent"
- android:layout_height="fill_parent"
- >
- <TextView
- android:layout_width="fill_parent"
- android:layout_height="wrap_content"
- android:text="@string/hello"
- />
- </linearlayout>
4 Configuring Strings.xml
[HTML]View Plaincopy
- <? XML version= "1.0" encoding="Utf-8"?>
- <resources>
- <string name="Hello">hello, this is a demo-to-picture before app start</string >
- <string name="app_name">loadpicturedemo</string>
- <style name= "MyTheme.NoTitleBar.CustomBackground" parent="@android: Theme.black" >
- <item name="Android:windowbackground"> @drawable/load</Item>
- <item name="Android:windownotitle">true</Item>
- <item name="Android:windowfullscreen">true</Item>
- <item name="Android:windowcontentoverlay"> @null</Item>
- </style>
- </Resources>
5 Configuring Androidmanifest.xml
[HTML]View Plaincopy
- <? XML version= "1.0" encoding="Utf-8"?>
- <manifest xmlns:android="http://schemas.android.com/apk/res/android"
- package="Com.timothy.load"
- android:versioncode="1"
- android:versionname="1.0">
- <uses-sdk android:minsdkversion="8" />
- <application android:icon="@drawable/icon" android:label="@string/app_name" >
- <activity android:name=". Loadactivity "
- android:configchanges="Orientation|keyboardhidden"
- android:theme="@style/mytheme.notitlebar.custombackground">
- <intent-filter>
- <action android:name="Android.intent.action.MAIN" />
- <category android:name="Android.intent.category.LAUNCHER" />
- </intent-filter>
- </Activity>
- <activity android:name=". Mainactivity ">
- </Activity>
- </Application>
- </manifest>
6 OK, compile and run
During the startup process:
Finish Startup:
Background image display during Android startup