"Possible overdraw: Root element paints background "

Viewed 21209

While running Android Lint on my Project I came across this warning

Possible overdraw: Root element paints background @drawable/main with a theme that also paints a background

Where inferred theme is @android:style/Theme.NoTitleBar.Fullscreen

Can someone explain to me why is this coming and how to remove it ??

My xml:

  <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
        android:layout_width="fill_parent"
        android:layout_height="fill_parent"
        android:background="@drawable/main" //***LINT warning***
        android:orientation="vertical"
        android:weightSum="3" >

The part of manifest where theme is defined

 <application
        android:icon="@drawable/ic_logo"
        android:label="@string/app_name"
        android:theme="@android:style/Theme.NoTitleBar.Fullscreen" >
5 Answers

In case you have fragments that replace each other in FragmentManager, you can remove additional drawings of the background.

So, if you have

val fragment = YourFragment.newInstance()
parentFragmentManager.beginTransaction().run {
    replace(R.id.container, fragment, YourFragment.TAG)
    addToBackStack(YourFragment.TAG)
}.commitAllowingStateLoss()

then the fragment will replace a current fragment and will have the background of an activity. In this case you can omit android:background="@color/..." of the fragment.

But if you remove android:background and add the fragment above a current fragment with add, it will have a trasparent background, so that views will overlap each other. You will see 2 fragments one above other.

To check this behaviour you can temporarily add <item name="android:windowBackground">@color/...</item> in AppTheme in styles.xml, as advised above.

A more brute force approach. In your custom theme.xml

<style name="MyTheme" parent="Theme.MaterialComponents.Light.Bridge">
     ...
    <item name="android:windowBackground">@color/white</item>
     ...
</style>
Related