在我的应用程序中,我有很多图层,而不是为每个图层设置背景图像,我想一劳永逸地设置背景。我怎样才能做到这一点?
答案 0 :(得分:10)
查看Apply a theme to an Activity or application以在整个应用程序中应用背景图像。
答案 1 :(得分:2)
为您的主题添加android:windowBackground
:
<!-- Base application theme. -->
<style name="AppTheme" parent="Theme.AppCompat.Light.DarkActionBar">
<!-- Customize your theme here. -->
<item name="colorPrimary">@color/colorPrimary</item>
<item name="colorPrimaryDark">@color/colorPrimaryDark</item>
<item name="colorAccent">@color/colorAccent</item>
<item name="android:windowBackground">@color/colorPrimaryDark</item>
</style>
当然,请确保您的清单使用主题为您的应用程序:
<?xml version="1.0" encoding="utf-8"?>
<manifest package="com.package.name"
xmlns:android="http://schemas.android.com/apk/res/android">
<application
android:theme="@style/AppTheme">
<activity android:name=".MainActivity">
<intent-filter>
<action android:name="android.intent.action.MAIN"/>
<category android:name="android.intent.category.LAUNCHER"/>
</intent-filter>
</activity>
</application>
</manifest>