1

I am trying to achieve this one custom underline for text-view so far I have reached very close, need help just to get it right.

I have tried to implement custom stroke in layer-list drawable then with the help of another layer-list, I added the inset tag and added the left and right parameter but couldn't hide either one. Please Help me out.

just_bottom_view

so_far_reached

custom_underline_text.xml

<?xml version="1.0" encoding="utf-8"?>
<layer-list xmlns:android="http://schemas.android.com/apk/res/android">
    <!--Custom text underline-->
    <item android:top="-3dp" android:left="-3dp" android:right="-3dp">
        <shape>
            <solid android:color="@android:color/transparent" />
            <stroke
                    android:width="2dp"
                    android:color="@color/mt_color_blue" />
        </shape>
    </item>

</layer-list>

shrink_left_right.xml

<?xml version="1.0" encoding="utf-8"?>
<layer-list xmlns:android="http://schemas.android.com/apk/res/android">
    <item>
        <inset android:drawable="@drawable/custom_underline_text"
               android:insetLeft="180dp" android:insetRight="180dp"/>
    </item>

</layer-list>

I use this custom underline property in a style so that I can change programmatically on run time.

styles.xml

<style name="Custom_text_select">
        <item name="android:background">@drawable/custom_underline_text</item>
        <item name="android:textColor">#000</item>
        <item name="android:paddingBottom">4dp</item>
    </style>
Zaraki596
  • 61
  • 8

1 Answers1

0

You can create Drawable like:

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

    <size android:height="1dp" />

    <solid android:color="@color/divider" />

</shape>

and set is as drawableBottom in your TextView

Peter Staranchuk
  • 1,343
  • 3
  • 14
  • 29