Brianjs
Brianjs

Reputation: 2239

Android App Custom Background

I feel like this is listed somewhere and is extremely easy but I cannot seam to find a straightforward answer. How do you set a custom background image. For instance set a PNG as the default background for my app instead of the black screen. Manifest, Layout, Main code thing? An example would be extremely amazing.

Upvotes: 2

Views: 4068

Answers (2)

JuniorIncanter
JuniorIncanter

Reputation: 1579

For those of you that are still looking to do this, the correct way to do it has changed slightly. Piggy-backing off of 500865's answer, here is the adjusted code:

<?xml version="1.0" encoding="utf-8"?>
<resources xmlns:android="http://schemas.android.com/apk/res/android">
  <style name="MyTheme" parent="android:Theme.Holo">
    <item name="android:background">@drawable/dummy_background_image</item>
  </style>
</resources>

Basically, you have to change windowBackground to just background, you have to include the line about xmlns:android, and you should (although not required) remove the .png extension.

Upvotes: 1

500865
500865

Reputation: 7120

xml/values/styles.xml

<?xml version="1.0" encoding="utf-8"?>
<resources>
  <style name="MyTheme" parent="android:Theme.Light"> <!-- Or any other parent you want -->
    <item name="android:windowBackground">@drawable/yourcustombackgroundimage.png</item>
  </style>
</resources>

and use this style in the manifest file.

<application android:theme="@style/MyTheme">

Upvotes: 6

Related Questions