SoulReaver313
SoulReaver313

Reputation: 543

How to draw outline stroke on text in TextView? (Kotlin)

I need to draw outline stroke on text in MaterialTextView. I saw that it is not that easy to do in older questions. (In this for example: How do you draw text with a border on a MapView in Android?). Is something changed right now? If we need to set it programmatically, can anyone help me with Kotlin method for this and explain how to make it? I saw answers but I don't know where to create attrs.xml file I never used it before.

Upvotes: 1

Views: 779

Answers (1)

lpizzinidev
lpizzinidev

Reputation: 13284

You could define a rectangle shape in the res/drawable folder, let's call it rect_border.xml:

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

    <stroke android:width="2dp" 
        color="#000" />

</shape>

And use it as android:background for your MaterialTextView:

<MaterialTextView
    ...
    android:background="@drawable/rect_with_border" />

Upvotes: 1

Related Questions