Search code examples
androidandroid-themeandroid-inflate

unable to set android:windowBackground Error inflation on item requires drawable child


In my application to avoid cold start I have defined a theme fro my splash activity and set its android:windowBackground property to my one of drawables but I am getting an inflation error.

tag requires a 'drawable' attribute or child tag defining a drawable

background_splash.xml:

<layer-list xmlns:android="http://schemas.android.com/apk/res/android">

    <item
        android:drawable="?attr/colorPrimary"/>

    <item>
        <bitmap
            android:gravity="center"
            android:src="@mipmap/ic_launcher"/>
    </item>

</layer-list>

styles:

<style name="SplashTheme" parent="Theme.AppCompat.Light.NoActionBar">
        <item name="android:windowBackground">@drawable/background_splash</item>
    </style>

Manifest:

 <activity
            android:name=".SplashActivity"
            android:configChanges="orientation|keyboardHidden"
            android:launchMode="singleTask"
            android:screenOrientation="portrait"
            android:theme="@style/SplashTheme"
            >
            <intent-filter>
                <action android:name="android.intent.action.MAIN" />

                <category android:name="android.intent.category.LAUNCHER" />
            </intent-filter>
        </activity>

Solution

  • I think the problem is in the background_splash.xml file in this line.

     android:drawable="?attr/colorPrimary"/>
    

    you have to change to this

    android:drawable="@color/colorPrimary"/>
    

    add your hex color code there and see the output.