How to set background color for xamarin forms android splash screen?

SreeeeSreeee ✭✭✭✭✭INMember ✭✭✭✭✭
edited November 2018 in Xamarin.Forms

Following is the splash screen code of my xamarin forms android:

<?xml version="1.0" encoding="utf-8"?>
<layer-list xmlns:android="http://schemas.android.com/apk/res/android">
    <item>
        <bitmap
        android:gravity="fill_horizontal|fill_vertical"
        android:src="@drawable/splashbg"/>
    </item>
    <item>
        <bitmap
        android:src="@drawable/icon"
        android:tileMode="disabled"
        android:gravity="center"/>
    </item>
</layer-list>

I wanna remove the first bitmap(named splashbg) and provide a background color for the entire page. How to give background color in xamarin android? Currently showing black color.

Try adding android:color="#00aff0" for layer list, but not working...

Best Answer

  • SreeeeSreeee ✭✭✭✭✭ IN ✭✭✭✭✭
    Accepted Answer

    Change the background color by below code:

    <?xml version="1.0" encoding="utf-8"?>
    <layer-list xmlns:android="http://schemas.android.com/apk/res/android">
      <item>
        <shape android:shape="rectangle">
          <solid android:color="@android:color/white" />
        </shape>
      </item>
      <item>
            android:src="@drawable/icon"
            android:tileMode="disabled"
            android:gravity="center"/>
      </item>
    </layer-list>
    

Answers

  • BillyLiuBillyLiu Xamurai Member, Xamarin Team Xamurai

    @Sreeee

    You could create a color in colors.xml:

    <resources>
      <color name="splash_background">#00aff0</color>
    </resources>
    

    Then change bitmap with:

     <color android:color="@color/splash_background"/>
    
  • SreeeeSreeee ✭✭✭✭✭ INMember ✭✭✭✭✭
    Accepted Answer

    Change the background color by below code:

    <?xml version="1.0" encoding="utf-8"?>
    <layer-list xmlns:android="http://schemas.android.com/apk/res/android">
      <item>
        <shape android:shape="rectangle">
          <solid android:color="@android:color/white" />
        </shape>
      </item>
      <item>
            android:src="@drawable/icon"
            android:tileMode="disabled"
            android:gravity="center"/>
      </item>
    </layer-list>
    
Sign In or Register to comment.