Mike K
Mike K

Reputation: 6491

How to underline text in Android Studio?

Looked everywhere, couldnt find a solution for this. Setting bold or italic is very easy, why is setting underline not as easy?

Here's my bit of relevant code:

   <LinearLayout
        android:orientation="horizontal"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:id="@+id/forgotpasswordHolder"
        android:layout_marginTop="10dp">

        <TextView
            android:layout_width="fill_parent"
            android:layout_height="wrap_content"
            android:text="Forgot your password?"
            android:id="@+id/labForgotpassword"
            android:textColor="#6BB08C"
            android:layout_weight="1"
            android:textStyle="bold|italic"
            android:layout_gravity="left"
            android:paddingLeft="20dp"
            android:textIsSelectable="true"
            android:singleLine="false" />

        <TextView
            android:layout_width="fill_parent"
            android:layout_height="wrap_content"
            android:text="Not a member?"
            android:id="@+id/signup"
            android:textColor="#6BB08C"
            android:layout_weight="1"
            android:textStyle="bold|italic"
            android:singleLine="false"
            android:layout_gravity="right"
            android:gravity="right"
            android:paddingRight="20dp"
            android:textIsSelectable="true" />
    </LinearLayout>

I have two "Forgot your password? and a "Not a member?" buttons, and I'd love it if I could underline the text(s).

Thanks in advance!

Upvotes: 4

Views: 7978

Answers (2)

Mir Rahed Uddin
Mir Rahed Uddin

Reputation: 1396

Just create a View below the TextView

As an example...

enter image description here

enter image description here

Upvotes: 2

Andrew Brooke
Andrew Brooke

Reputation: 12153

Use a string resource with <u> tags, like this

android:text="@string/forgotPassword"

Then in strings.xml, create a String

<string name="forgotPassword"><u>Forgot your password?</u></string>

Upvotes: 7

Related Questions