Customizing toggle animations between activity

Source: Internet
Author: User

Only those who are constantly looking for opportunities will seize the opportunity in time.


Content: Use theme to customize switch animations between activity

Most Android default activity between the animation switch effect, the right slide into the left slide, sometimes our needs may be required to switch all activity to fade the effect, this time may need to change the default switch style.


Example:


Here is the Res/layout/activity_main.xml layout file:

<relativelayout xmlns:android= "http://schemas.android.com/apk/res/android"    xmlns:tools= "http// Schemas.android.com/tools "    android:layout_width=" match_parent "    android:layout_height=" Match_parent "    android:background= "@drawable/c1" ></RelativeLayout>

here is the Res/layout/first.xml layout file:

<?xml version= "1.0" encoding= "Utf-8"? ><linearlayout xmlns:android= "http://schemas.android.com/apk/res/ Android "    android:layout_width=" match_parent "    android:layout_height=" Match_parent "    android: background= "@drawable/c2"    android:orientation= "vertical" ></LinearLayout>

here is the new Res/anim/fade_in.xml file:

<?xml version= "1.0" encoding= "Utf-8"? ><set xmlns:android= "Http://schemas.android.com/apk/res/android" >    <alpha        android:duration= "android:fromalpha="        0.0 "android:interpolator="        @android: Anim/accelerate_interpolator "        android:toalpha=" 1.0 "/></set>

Here is the new Res/anim/fade_out.xml file:

<?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 "/>

here is the Res/values/styles.xml file:

<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>  

here is the androidmanifest.xml file:

<?xml version= "1.0" encoding= "Utf-8"? ><manifest xmlns:android= "http://schemas.android.com/apk/res/        Android "package=" Com.example.custom "android:versioncode=" 1 "android:versionname=" 1.0 "> <uses-sdk android:minsdkversion= "8" android:targetsdkversion= "/> <application android:allowbackup=" Tru E "android:icon=" @drawable/ic_launcher "android:label=" @string/app_name "Android:theme=" @android: Styl E/theme.notitlebar "> <activity android:name=" com.example.custom.MainActivity "Android:                Label= "@string/app_name" android:theme= "@style/anim_fade" > <intent-filter> <action android:name= "Android.intent.action.MAIN"/> <category android:name= "Android.intent.catego Ry. LAUNCHER "/> </intent-filter> </activity> <activity android:name=". Appactivity "Android:theme=" @style/anim_fade ";</activity> </application></manifest> 

here is the Mainactivity.java main interface file:

public class Mainactivity extends Activity {private Handler handler=new Handler (); @Overrideprotected void OnCreate ( Bundle savedinstancestate) {super.oncreate (savedinstancestate); Setcontentview (R.layout.activity_main); Handler.postdelayed (New Runnable () {@Overridepublic void run () {Intent intent=new Intent (Mainactivity.this, Appactivity.class); startactivity (intent); Finish ();}}, 1000);}}

here is the Appactivity.java interface file:

public class Appactivity extends activity{@Overrideprotected void OnCreate (Bundle savedinstancestate) {super.oncreate ( Savedinstancestate); Setcontentview (R.layout.first);}}

Take your time and enjoy it

Customizing toggle animations between activity

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.