Search code examples
javaandroidandroid-edittexttextviewmultiline

EditText with textMultiLine not working


Here is my EditText. Why isn't allowing multiple lines?

<EditText
    android:id="@+id/edtextDesigner"
    android:layout_width="250dp"
    android:layout_height="wrap_content"
    android:layout_below="@+id/toggleText"
    android:layout_centerHorizontal="true"
    android:layout_marginTop="20dp"
    android:alpha="0.5"
    android:background="@drawable/rounded_corner"
    android:ems="10"
    android:lines="2"
    android:focusable="true"
    android:focusableInTouchMode="true"
    android:fontFamily="sans-serif-light"
    android:inputType="textMultiLine"
    android:padding="10dp"
    android:scrollHorizontally="false"
    android:textColor="#000000"
    android:textSize="16sp"
    android:typeface="sans"
    android:text=" "
    android:visibility="invisible" />

I've also set it programmatically.

        edit_View.setSingleLine(false);
        edit_View.setImeOptions(EditorInfo.IME_FLAG_NO_ENTER_ACTION);
        edit_View.setInputType(InputType.TYPE_CLASS_TEXT | InputType.TYPE_TEXT_FLAG_MULTI_LINE);

I'm at a complete loss as to why this isn't working.


Solution

  • I had this issue very recently. I found that setting the inputType programmaticly resets most options so you will have to set them after. I think changing your code to this may work:

    edit_View.setInputType(InputType.TYPE_CLASS_TEXT | InputType.TYPE_TEXT_FLAG_MULTI_LINE);
    edit_View.setSingleLine(false);
    edit_View.setImeOptions(EditorInfo.IME_FLAG_NO_ENTER_ACTION);