行业知识
Android Activity切换动画多种实现方式
2026-11-10 09:21:52
来源:互联网转载
1、AppTheme: 直接在主题中修改activity动画样式:
(1)在res下新建animindex.php/tags-522.html" >文件夹,在anim文件夹下分别创建
slide_in_from_bottom.xml:
slide_no.xml:
slide_out_from_bottom.xml:
(2)在res下新建values文件夹新建style.xml
style.xml:
@anim/slide_in_from_bottom @anim/slide_no @anim/slide_out_from_bottom
(3)在activity 用到的theme中加入android:windowAnimationStyle 属性:
@style/activity_animations
(4)然后在需要用到的activity中指定刚刚定义的theme
(5)如果需要所有页面都使用我们定制的样式,只需要在在整个application 的theme标签下指定即可:
*** ***
或者在theme文件添加自定义动画:
@style/activity_animations
2、activity.overridePendingTransition():
(1)A页面跳转到B页面
overridePendingTransition()必须写在startActivity()或者finish()之后
val intent = Intent(MainActivity@this,ServiceActivity::class.java)startActivity(intent)//finish()overridePendingTransition(R.anim.slide_in_from_bottom,R.anim.slide_no)
(2)B页面回到A页面需要重写finish方法,在finish的时候加上我们的动画效果
override fun finish() { super.finish() overridePendingTransition(R.anim.slide_no,R.anim.slide_out_from_bottom) }
下一篇:网页怎么设置关键字?