1

I want to create a splash screen containing the app name. How can I add text to a layer-list?

This is my splash screen file at the moment:

 <layer-list xmlns:android="http://schemas.android.com/apk/res/android">
        <item
            android:drawable="@android:color/white"
            android:gravity="fill_horizontal|fill_vertical" />
        <item> <!--APP NAME--></item>
    </layer-list>

I already tryed to create a png file with the app name but this caused some issues on different screen sizes.

I already tryed to create a png file with the text but it does not work for all screen sizes.

Zoe
  • 27,060
  • 21
  • 118
  • 148
naggab
  • 371
  • 4
  • 18
  • What does the layer-list that you tried look like? In what way does it not work (what was the result)? – LarsH May 13 '19 at 19:28
  • Apparently there is not a clean way to put text into a layer-list. See https://stackoverflow.com/questions/38161959/android-text-in-drawable-layer-list – LarsH May 13 '19 at 19:30
  • I updated the question with some code. It should be a white screen and in the center the app name. I do not know how I can add a text item. – naggab May 13 '19 at 19:32
  • How is it possible to creare a png that fits for most of the screens? I don not have much experience in those things. – naggab May 13 '19 at 19:35
  • did you got anything ? – A.s.ALI Mar 13 '20 at 11:50
  • No, I didn't. Since now I haven't tried other solutions. – naggab Mar 13 '20 at 15:13

2 Answers2

1

You can use a vector drawable (app_logo.xml) with your text as window background:

<?xml version="1.0" encoding="utf-8"?>

<layer-list xmlns:android="http://schemas.android.com/apk/res/android" android:opacity="opaque">
    
    <item android:drawable="@android:color/white"/>
    
    <item
        android:drawable="@drawable/app_logo"
        android:gravity="center" />

</layer-list>

Setting theme:

<style name="NewSplashTheme" parent="Theme.AppCompat.NoActionBar">
      <item name="android:windowBackground">@drawable/background_splash</item>
</style>

This will work correctly on API level >= 23, you should provide an alternative version of background_splash with raster graphics for previous API levels (see @Venky's answer).

Vadim Kotov
  • 8,084
  • 8
  • 48
  • 62
0

You can add an image in layer list

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

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

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

</layer-list>

In theme.xml

<style name="NewSplashTheme" parent="Theme.AppCompat.NoActionBar">
      <item name="android:windowBackground">@drawable/background_splash</item>
</style>

Don't forget to create an image with App Name

Ankit Tale
  • 1,924
  • 4
  • 17
  • 30