Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Android Activity Background Image

How do I use a background image in an Activity theme/style?

If I do this using a colour:

<style name="CustomTheme" parent="android:Theme.Light">     <item name="android:windowBackground">@color/custom_theme_color</item> </style> 

It works correctly, but if I replace the line with:

<item name="android:windowBackground">@drawable/splash_image</item> 

The image displays correctly, but all the content is squished into a tiny block in the top left corner of the screen. The shadow underneath the status bar is also cut off or messed.

I am using Mono for Android and the image is a valid nine-patch png.

like image 975
Matthew Avatar asked Jan 19 '12 15:01

Matthew


People also ask

How do I set activity images?

xml (or any activity you need to add image) and select the Design view. There you can see your Palette tool box on left side. You need to drag and drop ImageView. Select the image you want press Ok you can see the image on the Design view.

How do you set a picture as your background on an android?

Go to the 'Photos' app and select the photo you want to use. Click on the share icon on the lower left corner of the screen, then select 'Use as Wallpaper. ' Then choose to set the photo as either the lock screen, home screen or both.


2 Answers

I also don't use themes, so in the layout of the activity I would add

android:background="@drawable/splash_image" 
like image 168
VicVu Avatar answered Sep 18 '22 09:09

VicVu


My solution was change the android:windowBackground to android:background.

<?xml version="1.0" encoding="UTF-8" ?> <resources>   <style name="Theme.Splash" parent="android:Theme">     <item name="android:background">@drawable/splash</item>     <item name="android:windowNoTitle">true</item>   </style> </resources> 
like image 26
VeYroN Avatar answered Sep 18 '22 09:09

VeYroN