Search code examples
androidandroid-layoutandroid-lint

Make custom theme use null background (Android lint suggestion)


Im reading about the new Android Lint rules, and I find to prevent overdraw I should make my layouts with a background use a theme with null background, to prevent a background to be drawn if Im just gonna overwrite it. The problem is, how do I define a custom theme with null background?

Fail attempt 1 (doesn't compile):

<style name="NoTitleBarNoBackground" parent="@android:style/Theme.NoTitleBar">
        <item name="android:background">null</item>
</style>

Fail attempt 2 (warning persists):

<style name="NoTitleBarNoBackground" parent="@android:style/Theme.NoTitleBar">
        <item name="android:background">#00000000</item>
</style>

Solution

  • You can try this:

    <style name="CustomTheme" parent="@android:style/Theme.Light.NoTitleBar">
            <item name="android:windowContentOverlay">@null</item>
            <item name="android:windowBackground">@null</item>
        </style>
    

    Hope this helps!