Andrew Lam
Andrew Lam

Reputation: 3804

How to make TextView looks exactly like EditText?

How to make the whole TextView underline at the width of match parent like EditText?

This line of code only underlines the text, not the whole TextView.

textView.setPaintFlags(textView.getPaintFlags()| Paint.UNDERLINE_TEXT_FLAG);

The reason I want to use TextView is that setOnClickListener is triggered immediately in one tap for TextView, whereas two taps are required for a disabled editable EditText.

Upvotes: 21

Views: 13474

Answers (2)

blueware
blueware

Reputation: 5381

You can achieve this without writing many lines of xml attributes:

<TextView
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="Your text"
        android:hint="Your hint"
        style="@android:style/Widget.EditText"
        />

Upvotes: 12

sorianiv
sorianiv

Reputation: 4905

You can put the background of an EditText on your TextView. For example:

        <TextView
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:text="Your text"
            android:hint="My hint"
            android:textColor="?attr/editTextColor"
            android:background="?attr/editTextBackground"
            android:gravity="center_vertical"
            android:textAppearance="?android:attr/textAppearanceMediumInverse"
            />

You might want to change the text appearance to android:textAppearance="@style/TextAppearance.AppCompat.Button" if you are using an AppCompat theme.

Upvotes: 53

Related Questions