I am trying to use an android drawable xml.
<layer-list xmlns:android="http://schemas.android.com/apk/res/android" android:opacity="opaque">
<item android:drawable="@color/colorPrimary"/>
<item>
<bitmap
android:src="@drawable/ic_logo_black"
android:gravity="center"/>
</item>
<Text is it possible to insert some text here???/>
</layer-list>
For branding purposes, I would like to insert some text into this xml. (It doesn't even matter to me if the text is translated. I just want it so that whenever I am using this drawable xml, there are some text inserted in an area i specify)
Is this even possible? Can I actually put texts/characters in an drawable.xml? Is the only way for me to modify the image and add in text that way?
Thanks
How to put text in a drawable ? Basically, you have to extend the class Drawable and set the canvas to draw the text to a drawable. As you override the draw method, it will take the canvas and draw the text on defined locations.
One way to add Texts in your drawable layer-list is by creating a png file of the text and adding it using bitmap.
Sometimes you want an outline around your shape and to do that you can use the stroke tag. You can specify the width and color of the outline using android:width and android:color.
Unfortunately, you can't do that, For more Refer here.
Yes you can, if you just want to put some text inside of a button, use TextView with background set to your drawable.
Drawable resource
<?xml version="1.0" encoding="utf-8"?>
<selector xmlns:android="http://schemas.android.com/apk/res/android">
<item android:drawable="@drawable/action_map_icon_on_v2" android:state_pressed="true"/>
<item android:drawable="@drawable/action_map_icon_on_v2" android:state_selected="true"/>
<item android:drawable="@drawable/action_map_icon_off_v2"/>
</selector>
Layout file
<TextView
android:id="@+id/action_map"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerVertical="true"
android:paddingTop="5dp"
android:textSize="12sp"
android:textStyle="bold"
android:textAlignment="center"
android:text="MAP"
android:background="@drawable/action_map_button"
/>
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With