5

Voglio aggiungere uderline che copre la larghezza del genitore di riempimento sotto la vista testo per mostrare l'aspetto testuale come l'intestazione.come dare una linea sotto il Textview in Android

 <TextView 
      android:id="@+id/title" 
      android:layout_width="wrap_content" 
      android:layout_height="wrap_content" 
      android:layout_alignParentEnd="true" 
      android:layout_alignParentRight="true" 
      android:layout_alignParentTop="true" 
      android:layout_marginLeft="10dp" 
      android:layout_marginStart="10dp" 
      android:lines="1" 
      android:maxLines="2" 
      android:text="Large Text" 
      android:textAppearance="?android:attr/textAppearanceLarge" 
      android:textColor="@color/black" /> 

Grazie in anticipo

risposta

6

si può provare questo stile aggiuntivo

 <TextView 
      android:id="@+id/title" 
      style="@style/sectionHeader" 
      android:layout_width="wrap_content" 
      android:layout_height="wrap_content" 
      android:layout_alignParentEnd="true" 
      android:layout_alignParentRight="true" 
      android:layout_alignParentTop="true" 
      android:layout_marginLeft="10dp" 
      android:layout_marginStart="10dp" 
      android:lines="1" 
      android:maxLines="2" 
      android:text="Large Text" 
      android:textAppearance="?android:attr/textAppearanceLarge" 
      android:textColor="@color/black" /> 

a vostra styles.xml

<style name="sectionHeader" parent="android:Widget.Holo.Light.TextView"> 
    <item name="android:drawableBottom">@drawable/section_header</item> 
    <item name="android:drawablePadding">4dp</item> 
    <item name="android:layout_marginTop">8dp</item> 
    <item name="android:paddingLeft">4dp</item> 
    <item name="android:textAllCaps">true</item> 
    <item name="android:textColor">@color/emphasis</item> 
    <item name="android:textSize">14sp</item> 
    </style> 

fare un nome drawable come section_header.xml

<?xml version="1.0" encoding="utf-8"?> 
<shape 
    xmlns:android="http://schemas.android.com/apk/res/android" 
    android:shape="rectangle"> 
<size android:width="1000dp" android:height="0.5dp" /> 
<solid 
    android:color="@color/blue_grey"/> 
</shape> 

aggiungere colore al vostro color.xml

<color name="blue_grey">#607d8b</color> 
    <color name="emphasis">#31b6e7</color> 
+0

Grazie effettivamente ho troppi TextView. ora solo devo aggiungere lo stile per grazie mille –

+0

il tuo benvenuto Coder –

7

utilizzare questo codice sotto il TextView

<View 
     android:layout_width="match_parent" 
     android:layout_height="1dp" 
     android:background="@android:color/darker_gray" /> 
+0

'Android: layout_width = "fill_parent"' –

+2

FILL_PARENT è deprecato in livello di API 8 e l'uso MATCH_PARENT higherlevel API –

4

Se si desidera aggiungere a livello di codice poi fare questo

mTextView.setPaintFlags(mTextView.getPaintFlags()| Paint.UNDERLINE_TEXT_FLAG); 
1
put view on below textview: 

<View 
    android:layout_width="match_parent" 
    android:layout_height="1dp" 
    android:background="# your hex color code /> 
1

Se si aggiunge del testo alla cartella Textview from String, è possibile specificare come segue. Da

strings.xml

<string name="your_string_here"><u>This is an underline</u>.</string> 

Se si aggiunge testo in modo dinamico in questo caso si utilizza il seguente.

nella vostra attività: -

TextView textView = (TextView) view.findViewById(R.id.textview); 
SpannableString spannableStringObject= new SpannableString("Your text here"); 
spannableStringObject.setSpan(new UnderlineSpan(), 0, spannableStringObject.length(), 0); 
textView.setText(spannableStringObject); 
0

sua funziona per me.

tv.setPaintFlags(Paint.UNDERLINE_TEXT_FLAG);