41

I am trying to implement splash screen without any extra activities, using theme call in the manifest file's <activity/> tag.

In my styles.xml

<style name="splashTheme" parent="AppTheme">
        <item name="android:windowBackground">@drawable/splash</item>
</style>

here the drawable file splash.xml uses layer-list How do I add text to this layer list?

random.123
  • 65
  • 8
Katedral Pillon
  • 14,534
  • 25
  • 99
  • 199
  • I think this post answers your question: http://stackoverflow.com/questions/23299552/text-with-shapes-in-drawable-resource – Dr. Nitpick Jul 02 '16 at 16:16
  • 4
    Hmm, though you could do it with vector drawables according to this post: http://stackoverflow.com/questions/22850431/how-do-you-render-text-in-an-android-layer-list-xml-file I know that the new support library is backporting vector drawables for pre 21 devices but I am not certain if it will support this. It's worth a little investigation though if you are deadset on having a layer with text! – Dr. Nitpick Jul 02 '16 at 16:18
  • 1
    Just for the record, the first link does not even come close to addressing my problem. For Splash screens, my practice is to not use a layout file but to instead set the background in the theme. – Katedral Pillon Jul 02 '16 at 19:10
  • I gotcha and thanks for pointing that out, I was focusing solely on the part of your question about putting text in a layer-list drawable. I think the second link should be able to help you out in that case if you are using support library 23.2.0. https://medium.com/@chrisbanes/appcompat-v23-2-age-of-the-vectors-91cbafa87c88#.hfgzo7h4s – Dr. Nitpick Jul 02 '16 at 19:17
  • I ended up converting text into a vector drawable and then using as a bitmap in one of the layers – Leo DroidCoder Aug 18 '17 at 08:12

1 Answers1

9

One way to add Texts in your drawable layer-list is by creating a png file of the text and adding it using bitmap. Here is one example of it.

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

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

    <item android:bottom="150dp">
        <bitmap
            android:gravity="center"
            android:src="@drawable/logo"/>


    </item>
    <item android:top="60dp">
        <bitmap
            android:gravity="center"
            android:tint="@android:color/white"
            android:src="@drawable/text"/>
    </item>
</layer-list>
opticod
  • 795
  • 8
  • 10
  • 32
    while this might be a good hack, it doesn't allow solve the issue of putting text inside a layer-list – ahbou Dec 14 '16 at 17:58