Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Android: How to make TextView editable?

Tags:

android

How can I allow user to edit a TextView? Of course, I can use EditText instead, but I don't know how to customize it and also I've read in Android documentation that TextView can be editable. So I tried this:

<TextView android:id="@+id/tv"           android:layout_width="wrap_content"           android:layout_height="wrap_content"           android:textSize="80sp"           android:text="MyText"           android:editable="true"           android:singleLine="true"           android:inputType="text"           android:focusable="true"           android:clickable="true"           android:cursorVisible="true"/> 

But it still looks like common TextView. Does anyone know what I have missed? Or, may be, how to customize EditText for it look like TextView: without borders and background?

like image 572
uncle Lem Avatar asked Aug 21 '12 13:08

uncle Lem


People also ask

How do you make EditText editable?

The most reliable way to achieve that result is using UI. setReadOnly(myEditText, true) from this library. There are a few properties that have to be set, which you can check out in the source code. Possible duplicate of How to replicate android:editable="false" in code?

What is the difference between edit text and TextView android?

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.

What is editable type in android?

This is the class for text whose content and markup can both be changed. This is the interface for text whose content and markup can be changed (as opposed to immutable text like Strings). If you make a DynamicLayout of an Editable, the layout will be reflowed as the text is changed.


1 Answers

I know you don't want to use an EditText but it's really easy to make it look like a TextView.

<EditText      android:id="@+id/Id"      android:layout_width="fill_parent"      android:layout_height="wrap_content"      android:background="@android:color/transparent" >  </EditText> 

You can also use android:background="@null".

Edit:

The TextView's editable param does make it editable (with some restrictions).

If you set android:editable="true" you can access the TextView via the D-pad, or you could add android:focusableInTouchMode="true" to be able to gain focus on touch.

The problem is you cannot modify the existing text, and you cannot move the cursor. The text you write just gets added before the existing text.

like image 77
Benito Bertoli Avatar answered Oct 09 '22 17:10

Benito Bertoli