一:整个app都采用淡入淡出效果
1:在anim文件夹下定义动画文件
accelerate_interpolator.xml
<?xml version="1.0" encoding="utf-8"?>
<accelerateInterpolator />
decelerate_interpolator.xml<?xml version="1.0" encoding="utf-8"?>
<decelerateInterpolator />
fade_in.xml
<?xml version="1.0" encoding="utf-8"?>
<alpha xmlns:android="http://schemas.android.com/apk/res/android"
android:duration="@android:integer/config_longAnimTime"
android:fromAlpha="0.0"
android:interpolator="@anim/decelerate_interpolator"
android:toAlpha="1.0" />
fade_out.xml
<?xml version="1.0" encoding="utf-8"?>
<alpha xmlns:android="http://schemas.android.com/apk/res/android"
android:duration="@android:integer/config_mediumAnimTime"
android:fromAlpha="1.0"
android:interpolator="@anim/accelerate_interpolator"
android:toAlpha="0.0" />
2:定义styles.xml文件
<resources xmlns:android="http://schemas.android.com/apk/res/android">
<style name="AppBaseTheme" parent="android:Theme.Light"></style>
<style name="AppTheme" parent="AppBaseTheme">
<item name="android:windowAnimationStyle">@style/MyAnimation</item>
</style>
<style name="MyAnimation" parent="@android:style/Animation.Activity">
<item name="android:activityOpenEnterAnimation">@anim/fade_in</item>
<item name="android:activityOpenExitAnimation">@anim/fade_out</item>
<item name="android:activityCloseEnterAnimation">@anim/fade_in</item>
<item name="android:activityCloseExitAnimation">@anim/fade_out</item>
</style>
</resources>
3.在配置文件下配置主题
<application
android:allowBackup="true"
android:icon="@drawable/ic_launcher"
android:label="@string/app_name"
android:theme="@style/AppTheme" >
<activity
android:name="com.union.foodunion.WelcomeActivity"
android:label="@string/app_name" >
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
</application>
二:单个页面采用淡入淡出效果
在anim文件夹下定义动画文件(同上),然后在Actiivty中finish()或startActivity()后加一下代码:overridePendingTransition(R.anim.fade_in, R.anim.fade_out);