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.
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.
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.
I also don't use themes, so in the layout of the activity I would add
android:background="@drawable/splash_image"
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>
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With