Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Make EditText behave as a TextView in code

Tags:

android

How to make an EditText look like a TextView that is done in Java but not in XML..

I have seen how to do it using xml file like

style="@android:style/Widget.TextView"
android:editable="false"
android:cursorVisible="false"
android:longClickable="false"

but i want this to be done in java because i am not using any xml file for the layout.. everything is done in code itself .. I am trying to use GestureListener in my code .. it worked fine for TextView but not EditText So, anything to do for the EditText so that the GestureEvents can be implemented ?

Thanks,

like image 676
Siva Kumar Avatar asked Feb 14 '11 06:02

Siva Kumar


4 Answers

This is perfect way to make EditText as TextView.

Use in your EditText.

<EditText
          android:id="@+id/editTextPassword"
          android:layout_width="match_parent"
          android:layout_height="wrap_content"
          android:inputType="none"
          android:enabled="false"
          android:focusable="false"
          android:clickable="false"
          android:longClickable="false"
          android:inputType="none"/>
like image 109
vibhu norby Avatar answered Oct 29 '22 08:10

vibhu norby


EditText is a subclass of TextView - so except for editing, what applies to TextView applies to EditText as well.

like image 33
Heiko Rupp Avatar answered Nov 01 '22 10:11

Heiko Rupp


EditText Et; // initialize your edittext//

Et.setCursorVisible(false);
Et.setLongClickable(false);
Et.setClickable(false);
Et.setFocusable(false);
Et.setSelected(false);
Et.setKeyListener(null);
Et.setBackgroundResource(android.R.color.transparent);

And you'll never see it like an EditText again.

like image 10
Rajkiran Avatar answered Nov 01 '22 11:11

Rajkiran


add below two line into your edittext xml:

android:focusable="false"
android:inputType="none"
like image 4
Oneclickit It Consultuncy Avatar answered Nov 01 '22 09:11

Oneclickit It Consultuncy