Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to create transparent activity in android?

How to create transparent activity in android in that screen tap to dismiss button automatically dismiss the activity. please provide any solution.

enter image description here

like image 484
Narasimha Avatar asked May 02 '13 06:05

Narasimha


2 Answers

There are two ways to achieve this

  • use the following theme for activity.

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

  • Set background of the activity as a trans parent png image or a transparent code

eg.

android:background="@drawable/transparent_bg"

or

android:background="#33BBFFFF"

this is a semi transparent color

Related Links

How to make a background 20% transparent on Android

Understanding colors on Android (six characters)

  • To dismiss activity on tap implement onTouchListener and when touch event is detected call finish();

Hope it helps !!

like image 113
Rachita Nanda Avatar answered Oct 22 '22 17:10

Rachita Nanda


Works better with noTitleBar to create a full transparent activity

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

and remember extends your activity from Activity and not from AppCompactActivity

If you need to use AppCompact then declare a new theme:

<style name="Theme.AppCompat.Translucent" parent="Theme.AppCompat.NoActionBar">
    <item name="android:windowNoTitle">true</item>
    <item name="android:windowBackground">@android:color/transparent</item>
    <item name="android:colorBackgroundCacheHint">@null</item>
    <item name="android:windowIsTranslucent">true</item>
    <item name="android:windowAnimationStyle">@android:style/Animation</item>
</style>
like image 8
Pablo Cegarra Avatar answered Oct 22 '22 19:10

Pablo Cegarra