23

How to display transparent activity on the another activity without removing previous activity ?

I am able to create transparent activity but when i trying to push it using intent , the previous activity gets removed. I want my transparent activity on the top of previous activity.

Thanks!

Androjit
  • 255
  • 1
  • 2
  • 8

3 Answers3

38

declare your activity in manifest like this

 <activity android:name=".yourActivity" android:theme="@android:style/Theme.Translucent.NoTitleBar.Fullscreen"/>

and add a transperent background to your layout like this

 <?xml version="1.0" encoding="utf-8"?>
 <RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
  android:background = "any tranparent image name"  >
 </RelativeLayout>

Edit:

i think you are using this to open your transparent activity it finish your previous activity

Intent intent =new Intent(mContext,yourNewActivity.class);
startActivity(intent);
finish();

remove finish from here then your new activity in on top of previous activity like this

 Intent intent =new Intent(mContext,yourNewActivity.class);
 startActivity(intent);

Hope help..

Deepak Swami
  • 3,838
  • 1
  • 31
  • 46
  • 2
    yes i was doing exactly same as above by removing finish() statement my issue solved. Thanks! – Androjit Jul 05 '12 at 04:59
  • 5
    Nice solution. Note: The transparent background does not need to be a transparent image, it is enough to set: android:background="#00ffffff" – EZDsIt Jun 08 '16 at 13:54
26

For the AppCompat style, you can use the following code in your styles.xml, and the add that in your manifest.

styles.xml

<style name="Theme.Transparent" parent="Theme.AppCompat.Light.NoActionBar">
    <item name="android:windowIsTranslucent">true</item>   
    <item name="android:windowBackground">@android:color/transparent</item>
    <item name="android:windowContentOverlay">@null</item>   
    <item name="android:windowNoTitle">true</item>
    <item name="android:backgroundDimEnabled">true</item>
    <item name="colorPrimaryDark">@android:color/transparent</item>
</style>

Manifest

<activity android:name=".HomeActivity"
android:theme="@style/Theme.Transparent" />
Mohamed Jaleel Nazir
  • 5,776
  • 3
  • 34
  • 48
Nanda Gopal
  • 2,519
  • 1
  • 17
  • 25
1

I don't know why would you want that, but maybe a Custom dialog can do what you are looking for.

EDIT: This question has been answered before: How do I create a transparent Activity on Android?

I don't want to be rude, but I think you should do more research from your part. Also, can you post some code to see what exactly are you trying out, it also shows that you are trying something.

Community
  • 1
  • 1
0gravity
  • 2,682
  • 4
  • 24
  • 33
  • 2
    Have you used snapchat? When you take a picture, you press an emoji icon to add an emoji to image. And That icon shows a list of emojis and has subtabs to delete emojis you already added to the image. All that functionality can be squeezed into a dialog? – Daniel Viglione Jul 14 '17 at 02:59