varunkr
varunkr

Reputation: 5542

How to make an activity background completely transparent (not translucent)?

In my android activity, I need to make the background of the activity transparent. For that, I found solutions online saying to do this in theme.

<item name="android:windowIsTranslucent">true</item>
<item name="android:windowBackground">@android:color/transparent</item>

However this makes the activity background translucent i.e it isn't perfectly transparent, it is slightly grey. Is there a way to get a perfectly transparent background such that the screen below it is perfectly viisible. Thanks!

Upvotes: 0

Views: 154

Answers (2)

Quick learner
Quick learner

Reputation: 11457

Try this

<style name="TransparentTheme.Base" parent="Theme.AppCompat.DayNight.NoActionBar">
        <item name="colorPrimary">@color/primary</item>
        <item name="colorPrimaryDark">@color/primaryDark</item>
        <item name="colorAccent">@color/accent</item>
        <item name="android:windowIsTranslucent">true</item>
        <item name="android:windowBackground">@android:color/transparent</item>
        <item name="android:windowContentOverlay">@null</item>
        <item name="android:backgroundDimEnabled">false</item>
    </style>

Usage

<activity
        android:name=".activity"
        android:theme="@style/TransparentTheme.Base" />

Upvotes: 1

Ferran
Ferran

Reputation: 1448

Try this

    <item name="android:colorBackgroundCacheHint">@null</item>
    <item name="android:windowIsTranslucent">true</item>
    <item name="android:windowBackground">@color/transparent</item>

Upvotes: 1

Related Questions