How to remove Black background between start new activity during slide_left animation?
Asked Answered
D

6

37

When I call new activity by animation the background gets black.
How can I remove remove the black background?

For the animation I'm using:

getWindow().setBackgroundDrawableResource(R.drawable.mainbg_); 
overridePendingTransition (R.anim.push_up_in,0);
Diffractometer answered 24/6, 2011 at 13:18 Comment(0)
C
22

set the theme of that activity as transluscent in manifest file

android:theme="@android:style/Theme.Translucent"

so your code will be something like this

<activity android:name=".AdActivity"
        android:theme="@android:style/Theme.Translucent" />
Categorize answered 24/6, 2011 at 13:48 Comment(0)
F
78

Setting the Theme didn't work for me, but adding an exit animation did.

overridePendingTransition (R.anim.push_up_in,R.anim.hold);

For the exit animation, I just used an animation that does nothing.

<?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>
Finnigan answered 11/9, 2012 at 14:22 Comment(2)
This works. Note: android:duration should be equal to or greater than the duration of your animation of the entering activity.Empanel
Try android:duration="@android:integer/config_longAnimTime" to use the default animation duration for activitiesAnuran
D
42

All you really need, especially if you already got a theme set to the activity and don't want to use the Theme.Translucent suggested is add the following to your activity/app's theme:

<item name="android:windowIsTranslucent">true</item>
Dicky answered 3/5, 2013 at 21:55 Comment(4)
THANXXXX alot, you saved my dayNusku
this is better solution, because if we use app compat, we can't use @android:style/Theme.TranslucentHallelujah
this one is perfect solutionQuiteris
This don't work in huawei phone as translucent activity don't open in full screen mode.Diffractive
C
22

set the theme of that activity as transluscent in manifest file

android:theme="@android:style/Theme.Translucent"

so your code will be something like this

<activity android:name=".AdActivity"
        android:theme="@android:style/Theme.Translucent" />
Categorize answered 24/6, 2011 at 13:48 Comment(0)
M
11

If you are using the AppCompat ActionBarActivity you will need to use a theme that extends Theme.AppCompat

To give me the option to add background transparency to just the activities that needed it (ones launched using the intent flag_activity_new_task) but keep the background for the rest of the app.. I extended my main theme and set the transparent background options in that style.

<!-- 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>
Monah answered 12/2, 2015 at 11:40 Comment(0)
C
1

What cleared my problem was understanding following method :

overridePendingTransition (R.anim.A,R.anim.B);

First Argument A in this is applied to Incoming Activity. For Example If we Are going from X Activity to Y and we Apply above animation than A is applied to Y and B is Applied to X.

Similarly when we are coming back from Y to X on Back Press. if we apply SAME: than A is applied to Y and B is applied to X.

So it means while coming back from Y to X..Apply Hold Animation to X and Left to right to Y.

Hope it is of some use..

Chewy answered 26/4, 2016 at 10:40 Comment(0)
H
1

Add below attribute in your app then replace your own color :

<!-- Base application theme. -->
<style name="AppTheme" parent="Theme.AppCompat.NoActionBar">
     <item name="android:windowBackground">@color/colorBackground</item>
</style>

Below code effects to Activity Components if you use any overridePendingTransition(),it creates issue in transition while Activity changing it seems misbehaviour.So, don't use this code for prevent black background.

 android:theme="@android:style/Theme.Translucent"

                   OR

 <!-- Base application theme. -->
<style name="AppTheme" parent="Theme.AppCompat.NoActionBar">
       <item name="android:windowIsTranslucent">true</item>
</style>
Hunfredo answered 10/4, 2018 at 10:16 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.