Android Studio:EditText editable is deprecated How to use inputType
Solution 1
Use
android:clickable="false"
. but In case you want to use onclick listener for it. don't use
android:clickable="false"
.. Use
android:cursorVisible="false" android:focusable="false" .
Solution 2
The Code
In XML
<EditText
android:id="@+id/myEditText"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:hint="Hint"
android:focusable="false"
android:clickable="false"
android:cursorVisible="false"
/>
The Result
Java Code
You can achieve the same result at runtime with this code
EditText et = findViewById(R.id.myEditText);
et.setFocusable(false);
et.setClickable(false);
et.setCursorVisible(false);
Solution 3
If you are using any input type that is not kind of text or number like date or date and time you can use android:inputType="date"
or android:inputType="datetime"
or android:inputType="time"
. If you are not using any such kind of input type you can use android:inputType="none"
.
Solution 4
All the answers above suggesting XML markup changes doesnt seem to work. However I managed to achieve a similar result through code.
Simply use:
editText.setKeyListener(null);
Solution 5
Use this if you wanted to use click of edittext and disable input
android:clickable="false"
android:cursorVisible="false"
android:focusable="false"
android:focusableInTouchMode="false"
Related videos on Youtube
Wu Zijan
Updated on January 24, 2022Comments
-
Wu Zijan over 2 years
I want to realize
android:editable="false"
But it told me editable is deprecated ,you can use
inputType
instead.So I don't know how to realize it by using
inputType
.-
Ganesh Kanna over 7 years
-
Nilesh Senta over 7 yearsyou should try android:inputType="none"
-
jodm over 7 yearsPossible duplicate of EditText not editable
-
A. L. Flanagan over 6 yearsFYI: I found on my app that when
inputType="none"
, it still showed a cursor on the field. I had to seteditable="false"
to make it go away, anyway.
-
-
BabyishTank over 2 yearsthis does nothing, still able to enter text