2017-06-05 84 views
0

的中间留我想显示TextView的下方的虚线下划线,下面是我的代码Android的虚线下划线在TextView中

<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> 

和TextView中看起来如上 textview looks like this

任何人都可以帮助我下面的虚线到textview?

试图与drawableBottom也,但没有用

android:drawableBottom="@drawable/dashed_line" 
+0

尝试此链接https://mobikul.com/android-strike-textview/ –

+0

@Srikanth看我的代码 –

+0

嗨@ ND1010_,Vishva dave的代码工作,后来也会尝试你的代码。谢啦。 –

回答

2

使用此文件的虚线:

<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> 

然后添加

机器人:背景= “@绘制/ dashed_line”

+0

完美!有用。谢谢@Vishva dave –

+0

如果它解决了您的问题,请将其标记为正确的。 –

+0

标记为正确答案感谢家伙的帮助! –

1

您可以使用这样的事情。

TextView tv = (TextView) findViewById(R.id.mytext); 
tv.setText("This is strike-thru"); 
tv.setPaintFlags(tv.getPaintFlags() | Paint.STRIKE_THRU_TEXT_FLAG); 
+0

没有@Abhishek魅力我想我的虚线下划线底部的文本视图 –

1
<TextView ..... 
    .......... 
> 
<ImageView 
    android:layout_width="match_parent" 
    android:layout_height="5dp" 
    android:layerType="software" 
    android:src="@drawable/dotted_line" /> 

dotted_line.xml

<?xml version="1.0" encoding="utf-8"?> 
<shape xmlns:android="http://schemas.android.com/apk/res/android" 
    android:shape="line"> 
    <stroke 
     android:width="1dp" 
     android:color="@color/colorAccent" 
     android:dashGap="15px" 
     android:dashWidth="15dp" /> 
</shape> 
1

您也可以使用这样的(线下)

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

    contacttv.setPaintFlags(contacttv.getPaintFlags() | Paint.UNDERLINE_TEXT_FLAG); 
1

使用下面的代码添加下面的TextView虚线: dash.xml(绘制XML)

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

     <solid android:color="#ffffff" /> 

     <stroke 
      android:width="1dp" 
      android:dashGap="5dp" 
      android:dashWidth="5dp" 
      android:color="@android:color/black" /> 
    </shape> 
</item> 
</layer-list> 

并在你的textview xml中:

<TextView 
    android:id="@+id/segment" 
    android:layout_width="wrap_content" 
    android:layout_height="wrap_content" 
    android:background="@drawable/dash" 
    android:gravity="left" 
    android:text="First segment" 
    android:textSize="12sp" 
    android:layout_centerInParent="true"/>