无法设置 android:windowBackground 项目上的错误 inflation 需要可绘制的子项
unable to set android:windowBackground Error inflation on item requires drawable child
在我的应用程序中,为了避免冷启动,我已经为我的启动 activity 定义了一个主题,并将其 android:windowBackground
属性 设置为我的一个可绘制对象,但我得到了一个 inflation 错误。
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>
样式:
<style name="SplashTheme" parent="Theme.AppCompat.Light.NoActionBar">
<item name="android:windowBackground">@drawable/background_splash</item>
</style>
清单:
<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>
我认为问题出在 background_splash.xml
文件这一行。
android:drawable="?attr/colorPrimary"/>
你必须改成这个
android:drawable="@color/colorPrimary"/>
在那里添加您的十六进制颜色代码并查看输出。
在我的应用程序中,为了避免冷启动,我已经为我的启动 activity 定义了一个主题,并将其 android:windowBackground
属性 设置为我的一个可绘制对象,但我得到了一个 inflation 错误。
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>
样式:
<style name="SplashTheme" parent="Theme.AppCompat.Light.NoActionBar">
<item name="android:windowBackground">@drawable/background_splash</item>
</style>
清单:
<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>
我认为问题出在 background_splash.xml
文件这一行。
android:drawable="?attr/colorPrimary"/>
你必须改成这个
android:drawable="@color/colorPrimary"/>
在那里添加您的十六进制颜色代码并查看输出。