Friday, 25 October 2013

Android EditText to TextView conversion (UI only)

In order to make your EditText to function like Textview(look & feel) follow the below steps. 

Step 1: 
Assign ID to your EditText object
EditText edtText = (EditText)findViewById(R.id.YourID);

Step 2: 
Disable the edtText

edtText.setEnabled(false);

Step 3:
Disable cursor

edtText.setCursorVisible(false);

Step 4: 
Set Key listner as null.

edtText.setKeyListener(null);

Step 5:
 Make background Transparent

edtText.setBackgroundColor(Color.TRANSPARENT); 

Now check your EditText 

4 comments:

  1. Why not use styles?

    android:background="@android:color/transparent"
    android:editable="false"
    android:cursorVisible="false"

    In java you need to disable only KeyListener:
    edtText.setKeyListener(null);

    ReplyDelete
    Replies
    1. Dear Oleksii,
      Thats a good suggestion,
      Thanks will update soon .

      Delete
  2. Excellent tips. Really useful stuff .Never had an idea about this, will look for more of such informative posts from your side... Good job...Keep it up
    android app development perth | android app development sydney

    ReplyDelete