Search code examples
androidimagebackgroundwindow

windowBackground not showing image on device


I want a show an image as background for activities. I want to show an image (river_background) from drawable folder.

I used android:windowBackground in styles.xml for showing the image and it's working in simulator running api 23. The background image shows just fine. But when I run it on device(Moto G3) running api 23. The background image is not shown. Background is black.

Background image shows for a split second. But after the controls are shown, background goes black. Any help is appreciated

styles.xml

<resources>
    <style name="AppTheme.Transparent" parent="AppTheme">
        <item name="android:windowBackground">@drawable/river_background</item>
        <item name="windowActionBarOverlay">true</item>
    </style>

    <style name="AppTheme.Transparent.NoActionBar" parent="Theme.AppCompat.Light.NoActionBar">
        <item name="android:windowBackground">@drawable/river_background</item>
        <item name="windowActionBarOverlay">true</item>
    </style>
</resources>

v21/styles.xml

<resources>

    <style name="AppTheme.Transparent" parent="AppTheme">
        <item name="android:windowBackground">@drawable/river_background</item>
        <item name="windowActionBarOverlay">true</item>
        <item name="android:windowTranslucentStatus">true</item>
    </style>

    <style name="AppTheme.Transparent.NoActionBar" parent="Theme.AppCompat.Light.NoActionBar">
        <item name="android:windowBackground">@drawable/river_background</item>
        <item name="windowActionBarOverlay">true</item>
        <item name="android:windowTranslucentStatus">true</item>
    </style>

</resources>

Solution

  • Make sure you have the picture on all folders. Namely, Drawable-hdpi, Drawable-mdpi, Drawable-xdpi, Drawable-xxdpi and Drawable-xxxdpi.