安卓5.0 Transitions动画切换时状态栏不参与动画
程序员文章站
2022-05-05 14:21:32
...
1、在values-21文件夹下主题中设置Transitions动画
<style name="AppTheme" parent="@android:style/Theme.Light.NoTitleBar">
<item name="android:windowBackground">@drawable/aaa_cycle</item>
<!--<item name="android:windowIsTranslucent">true</item>-->
<item name="android:windowNoTitle">true</item>
<!--<item name="android:statusBarColor">@android:color/transparent</item>-->
<!--<item name="android:windowTranslucentStatus">false</item>-->
<!--允许使用transitions-->
<item name="android:windowActivityTransitions">true</item> <!--这一句必须添加,否则Activity动画无效-->
<item name="android:windowContentTransitions">true</item>
<item name="android:windowAllowEnterTransitionOverlap">true</item>
<item name="android:windowAllowReturnTransitionOverlap">true</item>
<!-- 指定进入和退出transitions -->
<item name="android:windowEnterTransition">@transition/transitionset_in</item>
<item name="android:windowExitTransition">@transition/transitionset_out</item>
<item name="android:windowSharedElementsUseOverlay">false</item>
</style>
2、在res文件夹下新建transition文件夹,并添加动画文件
<?xml version="1.0" encoding="utf-8"?>
<transitionSet xmlns:android="http://schemas.android.com/apk/res/android"
android:duration="300"
android:transitionOrdering="together">
<!--<fade android:fadingMode="fade_in">-->
<!--<targets>-->
<!--<target android:excludeId="@android:id/statusBarBackground" />-->
<!--<!–<target android:excludeId="@android:id/navigationBarBackground" />–>-->
<!--</targets>-->
<!--</fade>-->
<slide
android:slideEdge="end">
<targets>
<target android:excludeId="@android:id/statusBarBackground" /> <!-- 状态栏不参与动画过程 -->
<!--<target android:excludeId="@android:id/navigationBarBackground" />-->
</targets>
</slide>
<!--android:interpolator="@android:interpolator/decelerate_quad"-->
</transitionSet>
3、在代码中设置动画
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
startActivity(intent, ActivityOptions.makeSceneTransitionAnimation(this).toBundle());
} else {
startActivity(intent);
}
附赠一张*上大神思路的截图