Android Studio:EditText editable is deprecated How to use inputType

21,041

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

enter image description here

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"
Share:
21,041

Related videos on Youtube

Wu Zijan
Author by

Wu Zijan

Updated on January 24, 2022

Comments

  • Wu Zijan
    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.

  • BabyishTank
    BabyishTank over 2 years
    this does nothing, still able to enter text