Splash screen is resizing incorrectly

26,120

Solution 1

One issue is that windowBackground is sized to full screen size, inclding status bar at top or bottom of device. But the status bar is still shown. My response to Android Activity Background Image uses windowContentOverlay, which excludes the status bar.

Solution 2

For background drawable you should use layer-list. For example make bitmap_splash.xml:

<item android:drawable="@color/background"/>

<item>
    <bitmap
        android:gravity="center"
        android:src="@drawable/splashscreenimage" />
</item>

and then use it in your style:

...
<style name="Theme.Splash" parent="android:Theme">
    <item name="android:windowBackground">@drawable/bitmap_splash</item>
...
Share:
26,120
Telavian
Author by

Telavian

CTO of a small startup working to redefine how the billions of available consumer reviews are packaged for consumption.

Updated on July 09, 2022

Comments

  • Telavian
    Telavian almost 2 years

    I am using the style below to show a splash screen in my Xamarin Android application however the image always shows with incorrect sizing. I would like it to resize with the correct dimensions however it always expands to fit the screen.

    <?xml version="1.0" encoding="utf-8" ?>
    <resources>
      <style name="Theme.Splash" parent="android:Theme">
        <item name="android:windowBackground">@drawable/splashscreenimage</item>
        <item name="android:windowNoTitle">true</item>
        <item name="android:adjustViewBounds">true</item>
        <item name="android:scaleType">centerCrop</item>
      </style>
    </resources>
    

    The splash screen activity

      [Activity(MainLauncher = true, Theme = "@style/Theme.Splash", NoHistory = true)]
      public class SplashScreenActivity : Activity
      {
        protected override void OnCreate(Bundle bundle)
        {
          base.OnCreate(bundle);
    
          // Start our real activity
          StartActivity(typeof(LoginActivity));
        }
      }
    
  • Miha_x64
    Miha_x64 over 6 years
    ScaleType works only for ImageView, but the question is about windowBackground.
  • Hilal
    Hilal over 5 years
    I want to give the bitmap width however it is not supported under api 23. Is there anyway to make the logo bigger for all devices? thanks