Android开机启动动画
16lz
2021-01-24
本程序在别人的代码的基础上更改而成。
下载地址:http://download.csdn.net/detail/hong0220/4670232
核心代码:
SplashScreen.java
[java] view plain copy
- packagecom.yourname.main;
- importandroid.app.Activity;
- importandroid.content.Intent;
- importandroid.graphics.drawable.AnimationDrawable;
- importandroid.os.Bundle;
- importandroid.view.Menu;
- importandroid.view.MotionEvent;
- importandroid.widget.ImageView;
- publicclassSplashScreenextendsActivity{
- privateThreadmSplashThread;
- @Override
- publicvoidonCreate(BundlesavedInstanceState){
- super.onCreate(savedInstanceState);
- setContentView(R.layout.splash);
- finalImageViewsplashImageView=(ImageView)findViewById(R.id.SplashImageView);
- splashImageView.setBackgroundResource(R.drawable.flag);
- finalAnimationDrawableframeAnimation=(AnimationDrawable)splashImageView.getBackground();
- splashImageView.post(newRunnable(){
- @Override
- publicvoidrun(){
- frameAnimation.start();
- }
- });
- mSplashThread=newThread(){
- @Override
- publicvoidrun(){
- try{
- synchronized(this){
- wait(10000);
- }
- }
- catch(InterruptedExceptionex){
- }
- finish();
- }
- };
- mSplashThread.start();
- }
- @Override
- publicbooleanonTouchEvent(MotionEventevt)
- {
- if(evt.getAction()==MotionEvent.ACTION_DOWN)
- {
- synchronized(mSplashThread){
- finish();
- }
- }
- returntrue;
- }
- }
BootBroadcastReceiver.java
[java] view plain copy
- packagecom.yourname.main;
- importandroid.content.BroadcastReceiver;
- importandroid.content.Context;
- importandroid.content.Intent;
- publicclassBootBroadcastReceiverextendsBroadcastReceiver{
- staticfinalStringACTION="android.intent.action.BOOT_COMPLETED";
- @Override
- publicvoidonReceive(Contextcontext,Intentintent){
- if(intent.getAction().equals(ACTION)){
- IntentsayHelloIntent=newIntent(context,SplashScreen.class);
- sayHelloIntent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
- context.startActivity(sayHelloIntent);
- }
- }
- }
配置文件
AndroidManifest.xml
[plain] view plain copy
- <?xmlversion="1.0"encoding="utf-8"?>
- <manifestxmlns:android="http://schemas.android.com/apk/res/android"
- package="com.yourname.main"
- android:versionCode="1"
- android:versionName="1.0">
- <applicationandroid:icon="@drawable/icon"android:label="@string/app_name">
- <activity
- android:name="SplashScreen"
- android:theme="@style/Theme.Transparent">
- <intent-filter>
- <actionandroid:name="android.intent.action.MAIN"></action>
- <categoryandroid:name="android.intent.category.LAUNCHER"></category>
- </intent-filter>
- </activity>
- <receiverandroid:name=".BootBroadcastReceiver">
- <intent-filter>
- <actionandroid:name="android.intent.action.BOOT_COMPLETED"/>
- <categoryandroid:name="android.intent.category.LAUNCHER"/>
- </intent-filter>
- </receiver>
- </application>
- <uses-sdkandroid:minSdkVersion="7"/>
- </manifest>
layout/splash.xml
[plain] view plain copy
- <?xmlversion="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
[plain] view plain copy
- <?xmlversion="1.0"encoding="utf-8"?>
- <resources>
- <style
- name="SplashScreen">
- parent="@android:Animation"
- <itemname="android:windowEnterAnimation">@drawable/appear</item>
- <itemname="android:windowExitAnimation">@drawable/disappear</item>
- </style>
- <style
- name="Theme.Transparent"
- parent="android:Theme">
- <itemname="android:windowIsTranslucent">true</item>
- <itemname="android:windowBackground">@android:color/transparent</item>
- <itemname="android:windowNoTitle">true</item>
- <itemname="android:windowAnimationStyle">@style/SplashScreen</item>
- </style>
- </resources>
drawable/flag.xml
[plain] view plain copy
- <?xmlversion="1.0"encoding="utf-8"?>
- <animation-list
- xmlns:android="http://schemas.android.com/apk/res/android"
- android:id="@+id/flaganim"
- android:oneshot="false"
- >
- <itemandroid:drawable="@drawable/f03"android:duration="1000"/>
- <itemandroid:drawable="@drawable/f04"android:duration="1000"/>
- <itemandroid:drawable="@drawable/f05"android:duration="1000"/>
- <itemandroid:drawable="@drawable/f06"android:duration="1000"/>
- <itemandroid:drawable="@drawable/f07"android:duration="1000"/>
- <itemandroid:drawable="@drawable/f08"android:duration="1000"/>
- <itemandroid:drawable="@drawable/f09"android:duration="1000"/>
- <itemandroid:drawable="@drawable/f10"android:duration="1000"/>
- </animation-list>
drawable/appear.xml
[plain] view plain copy
- <?xmlversion="1.0"encoding="utf-8"?>
- <setxmlns: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>
Drawable/disappear.xml
<?xml version="1.0" encoding="utf-8"?><set xmlns:android="http://schemas.android.com/apk/res/android"><alphaandroid:interpolator="@android:anim/decelerate_interpolator"android:fromAlpha="1.0" android:toAlpha="0.0"android:duration="800"/></set>
更多相关文章
- android 读取 attr 资源
- Android(安卓)studio简易计算机
- Android中几种图片特效的处理的实现方法
- Android(安卓)去掉title bar的3个方法
- 从网上找的Android实用代码,记录备用
- 如何判断Android/IOS是否安装应用。
- Android(安卓)常用代码片小结
- (Android) ContentProvider 实例
- Android中用Handle做定时器,显示实时时间