Android activity设置透明windowIsTranslucent后动画无效问题

在做项目时要求弹出界面时无背景,并且带进出动画效果。无背景我们可以通过下面来设置:

	<style name="Theme.MyTranslucent" parent="@Android:style/Theme.DeviceDefault.Light">
	        <item name="android:windowBackground">@android:color/transparent</item>
	        <item name="android:colorBackgroundCacheHint">@null</item>
	        <item name="android:windowIsTranslucent">true</item>
	</style>

动画效果我们可以通过下面来设置:

	<style name="Theme.MyActivity" parent="@android:style/Animation.Activity">
	        <item name="android:taskOpenEnterAnimation">@anim/activity_open_enter</item>
	        <item name="android:taskOpenExitAnimation">@anim/activity_open_exit</item>
	        <item name="android:taskToFrontEnterAnimation">@anim/activity_open_enter</item>
	        <item name="android:taskToFrontExitAnimation">@anim/activity_open_exit</item>
	</style>

为了达到无背景又带动画效果,刚开始时我的设置为:

	<style name="MyAnimation" parent="@android:style/Animation.Activity">
	        <item name="android:taskOpenEnterAnimation">@anim/activity_open_enter</item>
	        <item name="android:taskOpenExitAnimation">@anim/activity_open_exit</item>
	        <item name="android:taskToFrontEnterAnimation">@anim/activity_open_enter</item>
	        <item name="android:taskToFrontExitAnimation">@anim/activity_open_exit</item>
	</style>

	<style name="Theme.MyTranslucent" parent="@android:style/Theme.DeviceDefault.Light">
	        <item name="android:windowBackground">@android:color/transparent</item>
	        <item name="android:colorBackgroundCacheHint">@null</item>
	        <item name="android:windowIsTranslucent">true</item>
	        <!-- Note that we use the base animation style here (that is no
	             animations) because we really have no idea how this kind of
	             activity will be used. -->
	        <item name="android:windowAnimationStyle">@android:style/MyAnimation</item>
	</style>

结果发现设置的动画无效果。后边查看了系统自带的styles,发现Android-SDK/platforms/android-19/data/res/values/styles.xml下有个Animation.Translucent的style,后面我将代码改为:

	<style name="Theme.NewCallScreen" parent="@android:style/Animation.Translucent">
	        <item name="android:taskOpenEnterAnimation">@anim/activity_open_enter</item>
	        <item name="android:taskOpenExitAnimation">@anim/activity_open_exit</item>
	        <item name="android:taskToFrontEnterAnimation">@anim/activity_open_enter</item>
	        <item name="android:taskToFrontExitAnimation">@anim/activity_open_exit</item>
	</style>

实现了需求。在此标记一下,以备复习之用。

文章目录
|