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 :)
This works for me:
<resources>
    <string name="your_string"><u>underline</u></string>
</resources>
Output:

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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With