2

MaxLines attribute in Edit text is not working:

<android.support.design.widget.TextInputLayout
        android:layout_width="match_parent"
        android:layout_marginBottom="5dp"
        android:paddingLeft="10dp"
        android:paddingRight="10dp"
        android:textColorHint="@color/colorAccent"
        android:layout_height="wrap_content">
    <EditText
        android:id="@+id/register_userName"
        android:maxLines="1"
        android:textColorHint="@color/colorAccent"
        android:textColor="@color/colorAccent"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:hint="Name" />
    </android.support.design.widget.TextInputLayout>

I'm using following in my gradle:

compileSdkVersion 25
buildToolsVersion '25.0.2'

Though I Have specified android:maxLines="1" for my edit text, the edit text shifting to new line I'm testing on Android 5.1, this worked fine on my previous apps but I recently updated my build tools and I'm not sure why android:maxLines="1" is not working as expected.

W4R10CK
  • 5,502
  • 2
  • 19
  • 30
Moulesh
  • 2,762
  • 1
  • 22
  • 32

4 Answers4

12

For now you should use inputType="text" with maxLines="1" for a single line.

Discussion on SO why it's deprecated: Is the xml attribute singleLine deprecated or not in Android?

Google issue: https://code.google.com/p/android/issues/detail?id=221762

Community
  • 1
  • 1
beeb
  • 1,615
  • 1
  • 12
  • 24
1

android:singleLine="true" is deprecated. Try to add

android:inputType="text"
Tomasz Czura
  • 2,414
  • 1
  • 14
  • 18
1

Add proper EditText line values:

android:lines="1"
android:minLines="1"
android:maxLines="1"

Using all 3 implies to single line.

W4R10CK
  • 5,502
  • 2
  • 19
  • 30
  • 1
    So now you have to provide 3 different descriptions to a single view, instead of one `singleLine`? As it is deprecated? Wow, that's an improvement towards better practice, gj google devs. – David Kasabji Jan 11 '17 at 15:35
  • @DavidK, its a hack that I came across, and it does not cause any big loose. – W4R10CK Jan 11 '17 at 15:40
  • 1
    It's cool if it works. But why deprecate a method that makes the same effect, just with one line? That is what I am wondering. – David Kasabji Jan 11 '17 at 15:41
  • and bravo this doesnt work like single property ... so yeah still single line property is required if you want inner text to be single line and restrict keyboard to show done instead of line break – Adeel Turk Apr 05 '17 at 06:53
1

Even though it seems to be working with android:inputType="text" the docs say it must be used with textMultiLine

Makes the TextView be at most this many lines tall. When used on an editable text, the inputType attribute's value must be combined with the textMultiLine flag for the maxLines attribute to apply.

andrei
  • 2,934
  • 2
  • 23
  • 36