How to set a background for whole application in Android?

16,877

Solution 1

Take a look at Apply a theme to an Activity or application to apply the background image across the whole application.

Solution 2

Add android:windowBackground to your theme:

<!-- 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>

And of course make sure your manifest uses the theme for you application:

<?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>
Share:
16,877

Related videos on Youtube

lomza
Author by

lomza

I'm an Android developer. You can check my tutorials and post about useful things, programming and other stuff on my blog http://lomza.totem-soft.com

Updated on July 09, 2020

Comments

  • lomza
    lomza almost 4 years

    In my application I have a lot of layers and instead of setting a background image to each of them, I want to set a background once and for all. How can I do that?

  • lomza
    lomza about 13 years
    Thank You! So, basically, I define a style with a background image, then in Manifest I put "android:theme" tag with my style and that's all?
  • Rajath
    Rajath about 13 years
    I haven't tried it for the case of a background image, but yes, that's the direction you need to take.
  • lomza
    lomza about 13 years
    It works! Though, I have few more problems, like implementing few themes in one activity/application, but I hope I'll handle it.
  • Nathaniel Ford
    Nathaniel Ford about 11 years
    You should include relevant code here, in case your link breaks.

Related