Text with shapes in drawable resource

Mykhailo Yuzheka picture Mykhailo Yuzheka · Apr 25, 2014 · Viewed 24.5k times · Source

Can i create text-shape in drawable resource? I was googling much but found nothing... Here is my drawable file:

<?xml version="1.0" encoding="utf-8"?>
   <layer-list xmlns:android="http://schemas.android.com/apk/res/android">
      <item>
         <shape android:shape="oval">
            <stroke android:width="3dp" android:color="#QQffQQ"/>
            <size android:width="120dp" android:height="120dp"/>
         </shape>
      </item>
      <item android:right="59dp" android:left="59dp">
         <shape android:shape="rectangle">
            <solid android:color="£22££20"/>
         </shape>
      </item>
      <item android:top="59dp" android:bottom="59dp">
         <shape android:shape="rectangle">
            <solid android:color="£20££20"/>
         </shape>
      </item>
      <item>
         <!--text should be here-->
      </item>
   </layer-list>

Answer

BVB picture BVB · Apr 25, 2014

No, you cannot do so. One idea is to set the Drawable as the background for a TextView and then simply set text in the TextView, which will appear above the other layers of your Drawable. Of course, this cannot be used for a splash screen, which requires a drawable resource as mentioned by zyamys in a comment below. An idea for that case is to generate static images with the text you are interested in. This unfortunately does not cover cases where the text is to be dynamic.