当我通过动画调用新的activity时,背景会变成黑色。
如何去除这个黑色的背景?
我使用的动画是:
getWindow().setBackgroundDrawableResource(R.drawable.mainbg_);
overridePendingTransition (R.anim.push_up_in,0);
当我通过动画调用新的activity时,背景会变成黑色。
如何去除这个黑色的背景?
我使用的动画是:
getWindow().setBackgroundDrawableResource(R.drawable.mainbg_);
overridePendingTransition (R.anim.push_up_in,0);
设置主题对我没有效果,但添加退出动画有用。
overridePendingTransition (R.anim.push_up_in,R.anim.hold);
退出动画,我只是使用了一个什么都不做的动画。
<?xml version="1.0" encoding="utf-8"?>
<set xmlns:android="http://schemas.android.com/apk/res/android">
<translate android:fromYDelta="0%p" android:toYDelta="0%p" android:duration="2000"/>
</set>
如果您已经设置了主题并且不想使用建议的Theme.Translucent,那么您真正需要的只是将以下内容添加到您的活动/应用程序主题中:
<item name="android:windowIsTranslucent">true</item>
在清单文件中将该活动的主题设置为半透明。
android:theme="@android:style/Theme.Translucent"
所以你的代码将会像这样
<activity android:name=".AdActivity"
android:theme="@android:style/Theme.Translucent" />
如果您正在使用AppCompat ActionBarActivity,则需要使用扩展Theme.AppCompat的主题。
为了让我有选项仅向需要它的活动(使用intent flag_activity_new_task启动的活动)添加背景透明度,但保留其余应用的背景...我扩展了我的主题并在该样式中设置了透明背景选项。
<!-- The main theme applied to the application or activity -->
<style name="Theme.app" parent="Theme.AppCompat.NoActionBar">
<!-- Your main app theme items go here-->
<item name="android:windowBackground">@drawable/some_drawable</item>
</style>
<!-- Transparent background for app / activity -->
<style name="Theme.app.Translucent" parent="Theme.app">
<item name="android:windowIsTranslucent">true</item>
<item name="android:windowBackground">@android:color/transparent</item>
<item name="android:colorBackgroundCacheHint">@null</item>
</style>
<!-- Base application theme. -->
<style name="AppTheme" parent="Theme.AppCompat.NoActionBar">
<item name="android:windowBackground">@color/colorBackground</item>
</style>
android:theme="@android:style/Theme.Translucent"
OR
<!-- Base application theme. -->
<style name="AppTheme" parent="Theme.AppCompat.NoActionBar">
<item name="android:windowIsTranslucent">true</item>
</style>
android:duration
应该等于或大于进入活动的动画持续时间。 - Alaa M.android:duration="@android:integer/config_longAnimTime"
来使用活动的默认动画持续时间。 - kds23