Edittext with a maximum of one line

Asked

Viewed 529 times

0

I see that to write in only one line on EditText needs to be with android:maxLines="1" and android:inputType="text", but I wonder if there’s any way to do this with android:inputType="number", because I just want the number pad to appear

Example:

<EditText
    android:inputType="number"
    android:digits="0123456789"
    android:maxLines="1"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:gravity="end"/>

Only when I do this, when it comes to the end of the line it goes to another line, keeping the size of the layout of a line, and without the android:maxLines="1" it increases the layout size of the EditText

  • The way you’re doing it, you’re not crossing a line, that’s correct. However, when the space to put the numbers is gone, they have to go somewhere if you keep typing. Have you tried the possibility to limit the amount of typed characters?

  • I understood that part, it’s the right part, but the question is whether there’s any way he behaves the same when it’s android:inputType="text", to stay in the same line and go giving side scroll on EditText and not on a new line. But I think it is not possible, must have a reason for such a limitation.

1 answer

1

It’s been a while, so I hope you’ve made it. If not, just use singleLine="true":

<com.google.android.material.textfield.TextInputEditText
  android:id="@+id/edt_observacao"
  android:layout_width="match_parent"
  android:layout_height="wrap_content"
  android:imeOptions="actionNext"
  android:inputType="textMultiLine"
  android:singleLine="true" />
  • Thanks for the answer, I’m not developing more for Android and I have no way to replicate the situation at the moment to test. I will not accept as an answer because documentation the singleLine is depreciated.

Browser other questions tagged

You are not signed in. Login or sign up in order to post.