Search code examples
androidxamarin.androidsplash-screennine-patch

Why does my 9-patch Android splash screen have a black rectangle in the middle of it?


I'm trying to use a 9-patch image as a splash screen, but I get a weird artefact when doing so.

I use the following style on the activity

<style name="AppTheme.Splash" parent="Theme.AppCompat.Light.NoActionBar">
    <item name="android:windowBackground">@drawable/splash_screen</item>
    <item name="android:windowNoTitle">true</item>
    <item name="android:windowFullscreen">true</item>
</style>

This references the following drawable

<?xml version="1.0" encoding="UTF-8" ?>
<layer-list xmlns:android="http://schemas.android.com/apk/res/android">
    <item>
        <color android:color="@color/splash_background" />
    </item>
    <item>
        <nine-patch 
            android:src="@drawable/test_splash" 
            android:tileMode="disabled"
            android:gravity="center" />
    </item>
</layer-list>

The 9-patch image has two scalable vertical regions---above and below "Middle". There is no horizontal scaling set.

9-patch image

What this ends up giving me is

bad screenshot

Where is that black bar 3/4 of the way down coming from?


Solution

  • I had the same issue. After scrubbing thru all of my splash.9.png files looking for the problem, I retreated and tried one that worked fine in another app. It produced the same artifact.

    It seems the issue is with the Theme.AppCompat.Light.NoActionBar. Try this instead:

      <style name="splashscreen" parent="android:Theme">
    

    It doesn't look exactly the same around the title bar and such, but it looks like a splash screen.