http://blog.csdn.net/esunshine1985/article/details/44302903
1.在Resources——values下新建styles.xml,添加内容如下:
- <resources xmlns:android="http://schemas.android.com/apk/res/android">
- <style name="AppTheme" parent="@android:style/Theme">
- <item name="android:windowNoTitle">true</item> <!-- 设置没有标题 -->
- <item name="android:textSize">20sp</item> <!-- 设置文本大小 -->
- <item name="android:textColor">#F34141</item>
- <item name="android:background">@android:color/background_light</item>
- <!-- 设置activity切换动画 -->
- <item name="android:windowAnimationStyle">@style/activityAnimation</item>
- </style>
- <!-- animation 样式 -->
- <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.在Resources下新建文件夹anim,在这个新建的文件夹下面新建四个文件,分别是
(1)slide_left_in.xml
- <?xml version="1.0" encoding="utf-8"?>
- <set
- xmlns:android="http://schemas.android.com/apk/res/android">
- <translate android:duration="300" android:fromXDelta="-100.0%p" android:toXDelta="0.0" />
- </set>
(2)slide_left_out.xml
- <?xml version="1.0" encoding="utf-8"?>
- <set
- xmlns:android="http://schemas.android.com/apk/res/android">
- <translate android:duration="300" android:fromXDelta="0.0" android:toXDelta="-100.0%p" />
- </set>
(3)slide_right_in.xml
- <?xml version="1.0" encoding="utf-8"?>
- <set
- xmlns:android="http://schemas.android.com/apk/res/android">
- <translate android:duration="300" android:fromXDelta="100.0%p" android:toXDelta="0.0" />
- </set>
(4)slide_right_out.xml
- <?xml version="1.0" encoding="utf-8"?>
- <set
- xmlns:android="http://schemas.android.com/apk/res/android">
- <translate android:duration="300" android:fromXDelta="0.0" android:toXDelta="100.0%p" />
- </set>
3.修改AndroidManifest.xml文件(红色标注的部分)
<application android:theme="@style/AppTheme"></application>
4.在MainActivity.cs中的切换按钮的代码:
- 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);
- };