Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Android splash screen stretches a logo on the full screen

I have a simple splash screen with a white background and the logo on the center of the screen. In a modern version of the Android, its work well but in 'old' versions of Android(for example API 22) my a logo is stretched on the full screen. How to make the logo splash screen look normal on all the version of Android (before API 19)? p.s. I`m not the Android developer.

drawable/background_splash.xml

<?xml version="1.0" encoding="utf-8"?>
<layer-list xmlns:android="http://schemas.android.com/apk/res/android">

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

  <item
    android:width="150dp"
    android:height="50dp"
    android:drawable="@mipmap/my_logo"
    android:gravity="center" />

</layer-list>

values/styles.xml

<resources>

    <style name="AppTheme" parent="Theme.AppCompat.Light.NoActionBar">
        <item name="android:statusBarColor">@color/white</item>
    </style>

    <style name="SplashTheme" parent="Theme.AppCompat.Light.NoActionBar">
        <item name="android:windowBackground">@drawable/background_splash</item>
        <item name="android:statusBarColor">@color/white</item>
    </style>

</resources>
like image 909
Yur D Avatar asked Sep 12 '18 13:09

Yur D


People also ask

What is the size of splash screen Android?

Splash Screen dimensions App icon with an icon background: This should be 240×240 dp, and fit within a circle of 160 dp in diameter. App icon without an icon background: This should be 288×288 dp, and fit within a circle of 192 dp in diameter.

How do you splash screen on Android?

The most straightforward way to create a simple splash screen was to create a dedicated theme overriding android:windowBackground with a drawable containing branding colors or a bitmap of a logo. The theme was set as an attribute of the launcher activity in AndroidManifest. xml.


2 Answers

Instead of using a simple <item/> tag, use a <bitmap/> tag inside of an <item>.

From the Layer List drawable documentation:

All drawable items are scaled to fit the size of the containing View, by default. [...] To avoid scaling items in the list, use a <bitmap> element inside the <item> element to specify the drawable and define the gravity to something that does not scale, such as "center".

<?xml version="1.0" encoding="utf-8"?>
<layer-list
    xmlns:android="http://schemas.android.com/apk/res/android">

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

    <item>
        <bitmap
            android:src="@mipmap/my_logo"
            android:gravity="center"/>
    </item>

</layer-list>
like image 113
Ben P. Avatar answered Sep 19 '22 18:09

Ben P.


This is because the attributes android:width and android:height were introduced in API level 23. The only solution I can think of if you want to show the same image with a relative size according to the screen size is to provide alternative bitmap resources.

Here is a link to the Android Developer Guide which explains this a bit further.

like image 45
MasterQueue Avatar answered Sep 19 '22 18:09

MasterQueue