-11

For Android EditText maxlines=true does not work if digits are applied and single line true is deprecated so anyone has any suggestions?

Phantômaxx
  • 37,901
  • 21
  • 84
  • 115
Rudee
  • 29
  • 2

3 Answers3

2

see this example

<EditText
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_margin="4dp"
        android:digits="1234567890ABCDEFGHIJKLMNOPQRSTUVWXYZ"
        android:maxLength="15"//used to set max character
        android:maxLines="1"/>//used to set max number of lines

enter image description here

Akshay Katariya
  • 1,464
  • 9
  • 20
0

Put this code in your activity

editText = (EditText) findViewById(R.id.editText);
editText.setSingleLine(true);

This is how your xml will look

<EditText
android:id="@+id/editText"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:digits="abcdefghijklmnopqrstuvwxyz"
android:maxLines="1"
android:textColor="@android:color/black"/>
Akshay Katariya
  • 1,464
  • 9
  • 20
Arjun Solanki
  • 236
  • 1
  • 11
  • 1
    put android:digits="abcdefghijklmnopqrstuvwxyz" and then check maxlines will not work. – Rudee Sep 07 '17 at 08:21
0

I think you didnt specify this parameter:

android:inputType="text" 

Without it you can even put new line in edit text. You could add also these attributes:

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

Though when I checked it without inputType attribute, it still didn't work. Hope I helped

M. Wojcik
  • 2,301
  • 3
  • 23
  • 31