Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to give underline to textview,tried many methods which are suggested [duplicate]

Tags:

android

I am trying to make a text view underlined in my Custom Dialog.

MY XML:

         <TextView
            android:id="@+id/tv_terms_policies"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:text="@string/terms_and_policies"           

            />

Methods which I have tried already:

Method 1.

    tvTerms=(TextView) findViewById(R.id.tv_terms_policies);
    String data="TERMS AND POLICIES";
    SpannableString content = new SpannableString(data);
    content.setSpan(new UnderlineSpan(), 0, data.length(), 0);
    tvTerms.setText(content);

Method 2.

    <string name="terms_plans"><u>TERMS AND POLICIES</u></string>

Method:3

    tvTerms=(TextView) findViewById(R.id.tv_terms_policies);
    String htmlString="<u>TERMS AND POLICIES</u>";
    tvTerms.setText(Html.fromHtml(htmlString));

unfortunatly these three methods are not working for me. Please suggest any other methods.. thnx in advnz :)

like image 547
Praanthan Avatar asked Oct 27 '25 13:10

Praanthan


2 Answers

This works for me:

<resources>
    <string name="your_string"><u>underline</u></string>
</resources>

Output:

enter image description here

like image 167
ManmeetP Avatar answered Oct 30 '25 02:10

ManmeetP


In yout string.xml

<string name="terms_plans"><u>TERMS AND POLICIES</u></string>

and than use in your xml

<TextView
android:id="@+id/tv_terms_policies"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="@string/terms_plans"           
/>

I hope it work.

like image 23
Payal Sorathiya Avatar answered Oct 30 '25 04:10

Payal Sorathiya



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!