2017-06-05 79 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"/>