Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to make TextView looks exactly like EditText?

Tags:

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.

like image 303
Andrew Lam Avatar asked Jan 17 '16 14:01

Andrew Lam


People also ask

What is the difference between an EditText and a TextView?

EditText is used for user input. TextView is used to display text and is not editable by the user. TextView can be updated programatically at any time.

Is EditText a subclass of TextView?

Android EditText is a subclass of TextView. EditText is used for entering and modifying text. While using EditText width, we must specify its input type in inputType property of EditText which configures the keyboard according to input.

Can TextView be edited?

You can fake a editable Textview. You just have to hide the textview when you touch it (make it "clickable"), replace it with an EditText, and display it again when the edit is over. Show activity on this post. TextView defines all capabilities found on EditText, but doesn't have built-in support to them.


1 Answers

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.

like image 188
sorianiv Avatar answered Oct 16 '22 16:10

sorianiv