Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

Tags:

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!

like image 659
Androjit Avatar asked Jul 02 '12 03:07

Androjit


People also ask

What is transparent activity?

In Android, we can create a transparent activity that will not be visible but your application will be running. The best part of this transparent activity is that you can create a transparent activity by just changing the resource file and we need not write the java or kotlin code for the same.

What function do you call to stop an activity and go back to the previous activity?

You opened the new activity from another activity with startActivityForResult. In that case you can just call the finishActivity() function from your code and it'll take you back to the previous activity.

What is Windowistranslucent?

You could make an Activity float on the other Activities with a translucent window background, e.g. PicCollage app. That provides the end users with a visually-pleasing UX.


2 Answers

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..

like image 147
Deepak Swami Avatar answered Sep 20 '22 12:09

Deepak Swami


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" /> 
like image 42
Nanda Gopal Avatar answered Sep 21 '22 12:09

Nanda Gopal