restrict edittext to single line restrict edittext to single line android android

restrict edittext to single line


Use android:maxLines="1" and android:inputType="text"

You forgot the android:maxLines attribute. And refer for android:inputType With your example, below will give this result:

<EditText     android:id="@+id/searchbox"      android:layout_width="match_parent"    android:layout_height="wrap_content"    android:maxLines="1"    android:inputType="text"    android:scrollHorizontally="true"    android:ellipsize="end"    android:layout_weight="1"    android:layout_marginTop="2dp"    android:drawablePadding="10dp"    android:background="@drawable/edittext"    android:drawableLeft="@drawable/folder_full"    android:drawableRight="@drawable/search"    android:paddingLeft="15dp"    android:hint="search..."></EditText>


Using android:singleLine="true" is deprecated.

Just add your input type and set maxline to 1 and everything will work fine

android:inputType="text"android:maxLines="1"


android:singleLine is now deprecated. From the documentation:

This constant was deprecated in API level 3.

This attribute is deprecated. Use maxLines instead to change the layout of a static text, and use the textMultiLine flag in the inputType attribute instead for editable text views (if both singleLine and inputType are supplied, the inputType flags will override the value of singleLine).

So you could just set android:inputType="textEmailSubject" or any other value that matches the content of the field.