19

Tested with Android 1.6(4) and 2.3.3(10).

I've made a minimalistic test application to demonstrate this, all it does is load the xml with:

setContentView(R.layout.main); 

and the xml is:

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:orientation="vertical" >

<TextView
    android:layout_width="fill_parent"
    android:layout_height="wrap_content"
    android:text="@string/hello" />

<EditText
    android:id="@+id/editText1"
    android:layout_width="fill_parent"
    android:layout_height="wrap_content"
    android:inputType="none"
    android:ems="10" >

</EditText>

The problem:

when setting inputType="none" the actual input type during execution becomes textMultiLine(0x00020001), I've checked it with a debugger.

On the other hand if I use inputType="text" it works as expected.

Is this a bug in Android?

Roland
  • 7,525
  • 13
  • 61
  • 124

8 Answers8

34

I had the same problem: defining the input type via xml did not work.

Then, to fix it, I set the input type programatically:

@Override
public void onActivityCreated(@Nullable Bundle savedInstanceState)
    {
    ...
    editText1= (EditText) super.getActivity().findViewById(R.id.editText1);
    editText1.setInputType(InputType.TYPE_NULL);    // none...
    ...
    }

That works for me.

fractalwrench
  • 4,028
  • 7
  • 33
  • 49
jsanmarb
  • 906
  • 12
  • 14
14

Setting InputType="none" xml doesn't work, but if you're using databinding then you can use the binding syntax to set Input type.

import the type..

<data> <import type="android.text.InputType" /> </data>

then bind the value

<EditText android:id="@+id/edit_text" android:inputType="@{InputType.TYPE_NULL}" />

Andronicus
  • 1,799
  • 1
  • 14
  • 28
  • 1
    With Material Library's `TextInputEditText`, setting `inputType` to `none` or `editable` to `false` doesn't help, but this works fine. The first answer is to do this in Java/Kotlin. – Lalit Fauzdar Apr 10 '21 at 05:59
  • this works, but in order to get the click listener to trigger i have to click twice. ideas? i already tried setting focusable and focusableInTouchMode to false – or_dvir Apr 17 '21 at 16:49
11

From what I can tell this is a bug in the android code. see this for refrence - How to make EditText not editable through XML in Android?

GalDude33 suggests-

    android:clickable="false" 
    android:cursorVisible="false" 
    android:focusable="false" 
    android:focusableInTouchMode="false"
Community
  • 1
  • 1
ghostbust555
  • 2,040
  • 16
  • 29
11

Use android:editable="false". Even though it's deprecated, it works when inputType doesn't.

sorianiv
  • 4,845
  • 1
  • 23
  • 27
  • 1
    Yes you are true. This is just the right works. Because inputType="none" is nonsense of deprecation update. – azwar_akbar Jul 04 '19 at 02:44
  • 1
    Actually this is the right answer, because EditText is editable = true by default and inputType is changed to TEXT in that case, it doesn't care of "none" in that case as this is also default value. See code of TextView ``` else if (inputType != EditorInfo.TYPE_NULL) { ... } ... else if (editable) { createEditorIfNeeded(); mEditor.mKeyListener = TextKeyListener.getInstance(); mEditor.mInputType = EditorInfo.TYPE_CLASS_TEXT; } ``` – AnoDest May 07 '20 at 12:25
  • 1
    @azwar_akbar Yes you are right. inputType="none" never works for anyone. You have to set it programatically in code using InputType.TYPE_NULL or resort to the deprecated android:editable="false" property in xml – Rafsanjani Sep 19 '20 at 13:24
4

Use this

 textView.setKeyListener(null);
Sampath Kumar
  • 4,433
  • 2
  • 27
  • 42
2

Setting the .xml like this works, however, I had to add another line because the cursor was visible.

android:focusable="false"
android:cursorVisible="false" 

It's strange that even after 2 years this "bug" is present, and the depreciated method works better than the suggested one.

Using this works as well, but you have to edit the background color in that case, unless you want the color different.

android:enabled="false"
Kreso
  • 53
  • 6
0

The following code works:

Use android:enabled="false"

0

This is a working example:-

<AutoCompleteTextView
                    android:id="@+id/autoComplete"
                    android:layout_width="wrap_content"
                    android:layout_height="match_parent"
                    android:layout_weight="1"
                    android:inputType="none"
                    android:enabled="false"
                    android:padding="15dp" />