Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How do I create a transparent Activity on Android?

I want to create a transparent Activity on top of another activity.

How can I achieve this?

like image 411
UMAR-MOBITSOLUTIONS Avatar asked Feb 01 '10 13:02

UMAR-MOBITSOLUTIONS


People also ask

What is transparent activity in Android?

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.

Can we create activity without UI in Android?

Explanation. Generally, every activity is having its UI(Layout). But if a developer wants to create an activity without UI, he can do it.


1 Answers

Add the following style in your res/values/styles.xml file (if you don’t have one, create it.) Here’s a complete file:

<?xml version="1.0" encoding="utf-8"?> <resources>   <style name="Theme.Transparent" parent="android:Theme">     <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:windowIsFloating">true</item>     <item name="android:backgroundDimEnabled">false</item>   </style> </resources> 

(The value @color/transparent is the color value #00000000 which I put in the res/values/color.xml file. You can also use @android:color/transparent in later Android versions.)

Then apply the style to your activity, for example:

<activity android:name=".SampleActivity" android:theme="@style/Theme.Transparent"> ... </activity> 
like image 169
gnobal Avatar answered Jan 01 '23 08:01

gnobal