How to Set Transparent Background in Android Layout?

Set the root layout background to transparent in XML:

`android:background=”@android:color/transparent”`

Example:

`

` android:layout_width=”match_parent”`

` android:layout_height=”match_parent”`

` android:background=”@android:color/transparent”>`

For a `ConstraintLayout`, use the same background attribute:

`android:background=”@android:color/transparent”`

If setting background programmatically:

`view.setBackgroundColor(Color.TRANSPARENT)`

If using a custom drawable, make sure its alpha is transparent

For the window background, set in theme:

`android:windowBackground=”@android:color/transparent”`

For an Activity dialog-style transparent window:

`getWindow().setBackgroundDrawable(new ColorDrawable(Color.TRANSPARENT))`

If needed, disable default dimming:

`getWindow().clearFlags(WindowManager.LayoutParams.FLAG_DIM_BEHIND)`

Suggested for You

Trending Today