本程序在别人的代码的基础上更改而成。
下载地址:http://download.csdn.net/detail/hong0220/4670232
核心代码:
SplashScreen.java
- package com.yourname.main;
- import android.app.Activity;
- import android.content.Intent;
- import android.graphics.drawable.AnimationDrawable;
- import android.os.Bundle;
- import android.view.Menu;
- import android.view.MotionEvent;
- import android.widget.ImageView;
- public class SplashScreen extends Activity {
- private Thread mSplashThread;
- @Override
- public void onCreate(Bundle savedInstanceState) {
- super.onCreate(savedInstanceState);
- setContentView(R.layout.splash);
- final ImageView splashImageView = (ImageView) findViewById(R.id.SplashImageView);
- splashImageView.setBackgroundResource(R.drawable.flag);
- final AnimationDrawable frameAnimation = (AnimationDrawable)splashImageView.getBackground();
- splashImageView.post(new Runnable(){
- @Override
- public void run() {
- frameAnimation.start();
- }
- });
- mSplashThread = new Thread(){
- @Override
- public void run(){
- try {
- synchronized(this){
- wait(10000);
- }
- }
- catch(InterruptedException ex){
- }
- finish();
- }
- };
- mSplashThread.start();
- }
- @Override
- public boolean onTouchEvent(MotionEvent evt)
- {
- if(evt.getAction() == MotionEvent.ACTION_DOWN)
- {
- synchronized(mSplashThread){
- finish();
- }
- }
- return true;
- }
- }
BootBroadcastReceiver.java
- package com.yourname.main;
- import android.content.BroadcastReceiver;
- import android.content.Context;
- import android.content.Intent;
- public class BootBroadcastReceiver extends BroadcastReceiver {
- static final String ACTION = "android.intent.action.BOOT_COMPLETED";
- @Override
- public void onReceive(Context context, Intent intent) {
- if (intent.getAction().equals(ACTION)){
- Intent sayHelloIntent=new Intent(context,SplashScreen.class);
- sayHelloIntent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
- context.startActivity(sayHelloIntent);
- }
- }
- }
配置文件
AndroidManifest.xml
- <?xml version="1.0" encoding="utf-8"?>
- <manifest xmlns:android="http://schemas.android.com/apk/res/android"
- package="com.yourname.main"
- android:versionCode="1"
- android:versionName="1.0">
- <application android:icon="@drawable/icon" android:label="@string/app_name">
- <activity
- android:name="SplashScreen"
- android:theme="@style/Theme.Transparent">
- <intent-filter>
- <action android:name="android.intent.action.MAIN"></action>
- <category android:name="android.intent.category.LAUNCHER"></category>
- </intent-filter>
- </activity>
- <receiver android:name=".BootBroadcastReceiver">
- <intent-filter>
- <action android:name="android.intent.action.BOOT_COMPLETED"/>
- <category android:name="android.intent.category.LAUNCHER"/>
- </intent-filter>
- </receiver>
- </application>
- <uses-sdk android:minSdkVersion="7" />
- </manifest>
layout/splash.xml
- <?xml version="1.0" encoding="utf-8"?>
- <LinearLayout
- xmlns:android="http://schemas.android.com/apk/res/android"
- android:layout_width="wrap_content"
- android:layout_height="wrap_content"
- android:id="@+id/TheSplashLayout"
- android:layout_gravity="center"
- >
- <ImageView
- android:layout_width="wrap_content"
- android:layout_height="wrap_content"
- android:id="@+id/SplashImageView"
- android:layout_gravity="center"
- >
- </ImageView>
- </LinearLayout>
values/styles.xml
- <?xml version="1.0" encoding="utf-8"?>
- <resources>
- <style
- name="SplashScreen">
- parent="@android:Animation"
- <item name="android:windowEnterAnimation">@drawable/appear</item>
- <item name="android:windowExitAnimation">@drawable/disappear</item>
- </style>
- <style
- name="Theme.Transparent"
- parent="android:Theme">
- <item name="android:windowIsTranslucent">true</item>
- <item name="android:windowBackground">@android:color/transparent</item>
- <item name="android:windowNoTitle">true</item>
- <item name="android:windowAnimationStyle">@style/SplashScreen</item>
- </style>
- </resources>
drawable/flag.xml
- <?xml version="1.0" encoding="utf-8"?>
- <animation-list
- xmlns:android="http://schemas.android.com/apk/res/android"
- android:id="@+id/flaganim"
- android:oneshot="false"
- >
- <item android:drawable="@drawable/f03" android:duration="1000" />
- <item android:drawable="@drawable/f04" android:duration="1000" />
- <item android:drawable="@drawable/f05" android:duration="1000" />
- <item android:drawable="@drawable/f06" android:duration="1000" />
- <item android:drawable="@drawable/f07" android:duration="1000" />
- <item android:drawable="@drawable/f08" android:duration="1000" />
- <item android:drawable="@drawable/f09" android:duration="1000" />
- <item android:drawable="@drawable/f10" android:duration="1000" />
- </animation-list>
drawable/appear.xml
- <?xml version="1.0" encoding="utf-8"?>
- <set xmlns:android="http://schemas.android.com/apk/res/android">
- <alpha
- android:interpolator="@android:anim/accelerate_interpolator"
- android:fromAlpha="0.0" android:toAlpha="1.0"
- android:duration="800"
- />
- </set>
<?xml version="1.0" encoding="utf-8"?>
<set xmlns:android="http://schemas.android.com/apk/res/android">
<alpha
android:interpolator="@android:anim/decelerate_interpolator"
android:fromAlpha="1.0" android:toAlpha="0.0"
android:duration="800"
/>
</set>