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.
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.
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.
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.
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.
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