Android
Activity
Transparent Activity
Android Development
Android UI

How do I create a transparent Activity on Android?

Master System Design with Codemia

Enhance your system design skills with over 120 practice problems, detailed solutions, and hands-on exercises.

Introduction

A transparent Activity is created by giving it a theme whose window background is transparent and whose content does not fully cover the screen. This is useful for overlay-style screens, permission explanations, or lightweight modal experiences, but it should be used carefully because the underlying activity remains visible.

Define a Transparent Theme

The core step is a theme with a transparent window background. In a classic XML-based Android app, that usually looks like this:

xml
1<style name="Theme.App.Transparent" parent="Theme.MaterialComponents.DayNight.NoActionBar">
2    <item name="android:windowIsTranslucent">true</item>
3    <item name="android:windowBackground">@android:color/transparent</item>
4    <item name="android:colorBackgroundCacheHint">@null</item>
5</style>

Then apply the theme in your manifest:

xml
<activity
    android:name=".TransparentActivity"
    android:theme="@style/Theme.App.Transparent" />

When this activity starts, the previous activity remains visible behind it.

Keep the Layout Transparent Too

The theme alone is not enough if the activity layout fills the screen with an opaque background. Your root view should stay transparent unless you intentionally want only part of the screen covered.

Example layout:

xml
1<?xml version="1.0" encoding="utf-8"?>
2<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
3    android:layout_width="match_parent"
4    android:layout_height="match_parent"
5    android:background="@android:color/transparent">
6
7    <LinearLayout
8        android:layout_width="match_parent"
9        android:layout_height="wrap_content"
10        android:layout_gravity="center"
11        android:background="@android:color/white"
12        android:orientation="vertical"
13        android:padding="24dp">
14
15        <TextView
16            android:layout_width="wrap_content"
17            android:layout_height="wrap_content"
18            android:text="Overlay content" />
19    </LinearLayout>
20</FrameLayout>

This creates a white card floating on top of the visible previous activity.

Consider Whether a Dialog or Bottom Sheet Is Better

A transparent activity can work, but it is not always the best tool. If the goal is a small overlay or confirmation screen, a DialogFragment or bottom sheet is often easier to reason about because it stays within the same activity stack.

Use a transparent activity when:

  • the overlay deserves its own lifecycle
  • you need separate intent entry points
  • the screen behaves more like an independent task step

Otherwise, lighter UI containers are usually easier to maintain.

Launch and Dismiss It Cleanly

You launch it like any other activity:

kotlin
val intent = Intent(this, TransparentActivity::class.java)
startActivity(intent)

Inside the transparent activity, keep dismissal explicit:

kotlin
1class TransparentActivity : AppCompatActivity() {
2    override fun onCreate(savedInstanceState: Bundle?) {
3        super.onCreate(savedInstanceState)
4        setContentView(R.layout.activity_transparent)
5    }
6
7    fun closeOverlay() {
8        finish()
9    }
10}

That keeps the navigation model predictable for both the user and the developer.

Understand Window Behavior

Transparency only affects what the user sees, not how the activity stack works. The transparent activity is still the foreground activity, so lifecycle callbacks, focus, back handling, and input all belong to it. Treat it like a real screen that happens to reveal content underneath, not like a passive visual effect.

Common Pitfalls

  • Setting a transparent theme but leaving the root layout background opaque. That makes the activity look non-transparent even though the window is configured correctly.
  • Using a transparent activity when a dialog or fragment would fit the UX better. Separate activities add lifecycle and navigation overhead.
  • Assuming touches automatically pass through to the activity behind. They usually do not; the top activity still owns the interaction surface.
  • Forgetting to test transitions and back navigation. Transparent activities can feel awkward if launch and dismissal are not deliberate.
  • Relying on old translucency flags without checking current theme and window behavior on modern Android versions.

Summary

  • A transparent activity needs both a transparent theme and a layout that does not hide the whole screen.
  • Apply the theme in the manifest and keep the window background transparent.
  • Use the pattern for overlay-style screens that truly benefit from their own activity lifecycle.
  • Do not expect touch events to pass through automatically to the activity underneath.
  • Consider a dialog or bottom sheet first if the UI does not need a separate activity.

Course illustration
Course illustration

All Rights Reserved.