转自:http://blog.csdn.net/zhangzhikaixinya/article/details/17001321
大部分Android App启动过程中,都会设置一个背景图片,直到App加载成功,图片消失。因此,这也是做Android App的基本技能之一。这个过程实现起来并不难。
总共需要以下内容:2个Activity,一张背景图,2个xml配置文件,String.xml,AndroidManifest写入配置信息。
1 准备一张背景图图片,命名为load,自己选择图片格式。放在drawable目录下
2 创建Load页面 LoadActivity.java及相关布局文件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 创建主页面 MainActivity.java及相关布局文件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 配置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 配置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, 编译运行
启动过程中:
完成启动:
时间: 2024-12-29 23:14:55