I want to create a transparent Activity on top of another activity.
How can I achieve this?
Assign the translucent theme to the activity that you want to make transparent in the Android manifest file of your project:
<activity
android:name="YOUR COMPLETE ACTIVITY NAME WITH PACKAGE"
android:theme="@android:style/Theme.Translucent.NoTitleBar" />
Just let the activity background image be transparent. Or add the theme in the XML file:
<activity android:name=".usual.activity.Declaration" android:theme="@android:style/Theme.Translucent.NoTitleBar" />
Using Theme.NoDisplay
will still work… but only on older Android devices. On Android 6.0 and higher, using Theme.NoDisplay without calling finish()
in onCreate() (or, technically, before onResume())
will crash your app. This is why the recommendation is to use Theme.Translucent.NoTitleBar
, which does not suffer from this limitation.”
in addition to the above answers:
to avoid android Oreo related crash on activity
<style name="AppTheme.Transparent" parent="@style/Theme.AppCompat.Dialog">
<item name="windowNoTitle">true</item>
<item name="android:windowCloseOnTouchOutside">false</item>
</style>
<activity
android:name="xActivity"
android:theme="@style/AppTheme.Transparent" />
If you are using AppCompatActivity
then add this in styles.xml
<style name="TransparentCompat" parent="@style/Theme.AppCompat.Light.DarkActionBar">
<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>
In manifest
file you can add this theme to activity tag like this
android:theme="@style/TransparentCompat"
for more details read this article
Assign it the Translucent theme
android:theme="@android:style/Theme.Translucent.NoTitleBar"