http://blog.csdn.net/esunshine1985/article/details/44302903
1. Create a new Styles.xml under Resources--values and add the following:
[HTML]View PlainCopy
- <resources xmlns:android="http://schemas.android.com/apk/res/android">
- <style name="Apptheme" parent="@android: Style/theme">
- <item name="Android:windownotitle">true</Item> <!-- Set no title --
- <item name="android:textsize">20sp</Item> <!--setting Text size--
- <item name="Android:textcolor"> #F34141</Item>
- <item name="Android:background"> @android: Color/background_light</Item >
- <!--set activity toggle Animation --
- <item name="Android:windowanimationstyle"> @style/activityanimation</ Item>
- </style>
- <!--animation style --
- <style name="activityanimation" parent="@android: Style/animation">
- <item name="android:activityopenenteranimation"> @anim/slide_right_in</Item >
- <item name="android:activitycloseexitanimation"> @anim/slide_right_out</ Item>
- <item name="android:activityopenexitanimation"> @anim/slide_left_out</Item >
- <item name="android:activitycloseenteranimation"> @anim/slide_left_in</ Item>
- </style>
- </Resources>
2. Under Resources, create a new folder Anim, under this new folder, create four new files, respectively
(1) Slide_left_in.xml
[HTML]View PlainCopy
- <? XML version= "1.0" encoding="Utf-8"?>
- <set
- xmlns:android="http://schemas.android.com/apk/res/android">
- <translate android:duration= "android:fromxdelta=" -100.0%p " android:toxdelta= "0.0" />
- </Set>
(2) Slide_left_out.xml
[HTML]View PlainCopy
- <? XML version= "1.0" encoding="Utf-8"?>
- <set
- xmlns:android="http://schemas.android.com/apk/res/android">
- <translate android:duration="android:fromxdelta=" 0.0 "android:toxdelta=" - 100.0%p " />
- </Set>
(3) Slide_right_in.xml
[HTML]View PlainCopy
- <? XML version= "1.0" encoding="Utf-8"?>
- <set
- xmlns:android="http://schemas.android.com/apk/res/android">
- <translate android:duration= "android:fromxdelta=" 100.0%p " android:toxdelta= "0.0" />
- </Set>
(4) Slide_right_out.xml
[HTML]View PlainCopy
- <? XML version= "1.0" encoding="Utf-8"?>
- <set
- xmlns:android="http://schemas.android.com/apk/res/android">
- <translate android:duration= "android:fromxdelta=" 0.0 " android:toxdelta=" 100.0%p " />
- </Set>
3. Modify the Androidmanifest.xml file (the section marked in red)
<application android:theme= "@style/apptheme"></application>
4. The Code of the toggle button in MainActivity.cs:
[HTML]View PlainCopy
- button. Click + = Delegate
- {
- Intent Intent = new Intent ();
- Intent. SetClass (This, typeof (Activity2));
- StartActivity (Intent);
- Overridependingtransition (Resource.Animation.slide_left_in, Resource.Animation.slide_right_out);
- };
Xamarin.android Activity Animation Switching effect implementation