Search code examples
androidandroid-layoutandroid-widget

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


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?


Solution

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