Android EditText inputType="none" doesn't work, becomes "textMultiLine"

18

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?

android
android-layout
android-widget
asked on Stack Overflow Apr 18, 2012 by Roland • edited Oct 10, 2017 by Roland

5 Answers

31

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.

answered on Stack Overflow Aug 10, 2015 by jsanmarb • edited Mar 28, 2017 by fractalwrench
13

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}" />

answered on Stack Overflow Jul 6, 2017 by Andronicus
10

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

answered on Stack Overflow Feb 25, 2014 by sorianiv
9

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"
answered on Stack Overflow Apr 18, 2012 by ghostbust555 • edited May 23, 2017 by Community
3

Use this

 textView.setKeyListener(null);
answered on Stack Overflow Mar 10, 2014 by Sampath Kumar

User contributions licensed under CC BY-SA 3.0