Most of the Android system default activity between the animation switch effect is, the right slide into the left slide; sometimes our needs may be to require all activity to be switched to fade in, and this time you may need to change the default switching style.
Here's the implementation:
First create the Anim folder under the Res folder, and then create the Fade_in.xml and fade_out.xml two animation resources inside
Fade_in.xml
<?xml version= "1.0" encoding= "Utf-8"?> <alpha xmlns:android=
"http://schemas.android.com/apk/res/" Android "
android:duration=" "
android:fromalpha=" 0.0 "
android:interpolator=" @android: anim/ Accelerate_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:fromalpha=" 1.0 "
android:interpolator=" @android: anim/ Accelerate_interpolator "
android:toalpha=" 0.0 "/>
It is then written in the Resources tab in the Styles.xml under the Values folder:
<style name= "Anim_fade" parent= "Android:Theme.NoTitleBar" >
<item name= "Android:windowanimationstyle" > @style/fade</item>
</style>
<style name= "Fade" 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>
The final step is to add Android:theme= "@style/anim_fade" in the statement of the activity in Androidmanifest.xml.
<?xml version= "1.0" encoding= "Utf-8"?> <manifest xmlns:android= "http://schemas.android.com/apk/res/" Android "package=" Com.example.customanimationforactivity "android:versioncode=" 1 "android:versionname=" 1.0 "> & LT;USES-SDK android:minsdkversion= "android:targetsdkversion=" "/> <application android:allowBackup=" True "android:icon=" @drawable/ic_launcher "android:label=" @string/app_name "Android:theme=" @android: style/ Theme.notitlebar "> <activity android:name=" com.example.customanimationforactivity.MainActivity "Android: Label= "@string/app_name" android:theme= "@style/anim_fade" > <intent-filter> <action android:name= "Andro Id.intent.action.MAIN "/> <category android:name=" Android.intent.category.LAUNCHER "/> </intent-filter&
Gt </activity> <activity android:name= ". Appactivity "Android:theme=" @style/anim_fade "> </activity> </application> </manifest>
Post the code for the splash activity:
Package com.example.customanimationforactivity;
Import android.app.Activity;
Import android.content.Intent;
Import Android.os.Bundle;
Import Android.os.Handler;
public class Mainactivity extends activity
{
private Handler Handler = new Handler ();
@Override
protected void onCreate (Bundle savedinstancestate)
{
super.oncreate (savedinstancestate);
Setcontentview (r.layout.activity_main);
Handler.postdelayed (New Runnable ()
{
@Override public
Void Run ()
{
Intent Intent = new Intent (Mainactivity.this, appactivity.class);
StartActivity (intent);
Finish ();
}
, 1000);
}
SOURCE Download: Http://xiazai.jb51.net/201609/yuanma/CustomAnimation (jb51.net). rar
The above is the entire content of this article, I hope to help you learn, but also hope that we support the cloud habitat community.