Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Android Studio:EditText editable is deprecated How to use inputType

Tags:

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.

like image 838
Wu Zijan Avatar asked Jan 24 '17 13:01

Wu Zijan


People also ask

How do I edit EditText Uneditable?

If you want your disabled EditText to look the same as your enabled one, you should use android:enabled="false" in combination with android:textColor="..." . Show activity on this post. Used this if you have an icon to be clickable, this works for me.

How do you make EditText not editable and clickable?

For the above requirement the solution in XML is android:editable="false" but I want to use this in Java. et. setKeyListener(null); It makes the EditText not EDITABLE but at the same time it makes it non clickable as well.

Is EditText deprecated?

Android Studio:EditText editable is deprecated How to use inputType.

How do I turn an editable into a string?

Simply use toString() on the Editable instance to get String.


2 Answers

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" .

like image 119
SilenceCodder Avatar answered Sep 19 '22 12:09

SilenceCodder


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);
like image 44
Rohit Singh Avatar answered Sep 22 '22 12:09

Rohit Singh