如何在Android中为整个应用程序设置背景?

lom*_*mza 10 android background

在我的应用程序中,我有很多图层,而不是为每个图层设置背景图像,我想一劳永逸地设置背景.我怎样才能做到这一点?

raj*_*ath 11

查看将主题应用于活动或应用程序以在整个应用程序中应用背景图像.


Ada*_*hns 10

添加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>
Run Code Online (Sandbox Code Playgroud)

当然,请确保您的清单为您的应用程序使用主题:

<?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>
Run Code Online (Sandbox Code Playgroud)