Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Android dotted underline is staying in middle of textview

Tags:

android

xml

I want to show a dotted underline below the textview, following are my codes

<TextView
  android:id="@+id/contact_num"
  android:layout_width="wrap_content"
  android:layout_height="wrap_content"
  android:paddingTop="4dp"
  android:text="1234567890"
  android:background="@drawable/dashed_line"
  android:layerType="software"
  android:textSize="20dp" />

dashed_line.xml

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

    <stroke
        android:color="@color/oceanBlue"
        android:dashWidth="2dp"
        android:dashGap="3dp"
        android:width="1dp"/>
</shape>

and the textview looks as above textview looks like this

can anyone help me to get the dotted line below to the textview?

tried with drawableBottom also but no use

android:drawableBottom="@drawable/dashed_line"
like image 870
Srikanth K Avatar asked Nov 22 '25 09:11

Srikanth K


2 Answers

use this file for dotted line :

<layer-list xmlns:android="http://schemas.android.com/apk/res/android" >

    <item
        android:left="-5dp"
        android:right="-5dp"
        android:top="-5dp">
        <shape
            android:shape="rectangle">

            <stroke
              android:color="@color/oceanBlue"
              android:dashWidth="2dp"
              android:dashGap="3dp"
              android:width="1dp"/>
        </shape>
    </item>

</layer-list>

then add

android:background="@drawable/dashed_line"

like image 182
Vidhi Dave Avatar answered Nov 23 '25 22:11

Vidhi Dave


You can also use like this(Under Line)

    TextView contacttv = (TextView) findViewById(R.id.contactTextView);

    contacttv.setPaintFlags(contacttv.getPaintFlags() | Paint.UNDERLINE_TEXT_FLAG);
like image 40
Tashidev Avatar answered Nov 23 '25 23:11

Tashidev



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!