Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Single line EditText in Android

I am trying to make the edittext single line. The edittext does comes up as single line but on pressing enter it the cursor comes to the second line and I need to stop this. The singleLine attribute is deprecated so I do not want to use that.

<EditText
    android:id="@+id/txtSearch"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:layout_marginLeft="5dp"
    android:drawablePadding="5dp"
    android:lines="1"
    android:maxLines="1"
    android:inputType="none"
    android:scrollHorizontally="true"
    android:paddingLeft="5dp"
    android:textSize="12sp" />

Can someone let me know what am I goind wrong over here ?

like image 805
thefrugaldev Avatar asked Mar 29 '13 07:03

thefrugaldev


People also ask

What is Imeoption Android?

android:imeOptions="actionSend" /> You can then listen for presses on the action button by defining a TextView.OnEditorActionListener for the EditText element. In your listener, respond to the appropriate IME action ID defined in the EditorInfo class, such as IME_ACTION_SEND . For example: Kotlin Java.


2 Answers

Set android:inputType to something different than "none", use "text", "number" or whatever should be entered in the EditText. This way you can make the EditText single-lined. (Of course you shouldn't use "textMultiLine" then ;))

like image 81
chuky Avatar answered Oct 03 '22 05:10

chuky


Use this

android:singleLine="true"

instead of,

android:lines="1"
android:maxLines="1"
like image 26
Linga Avatar answered Oct 03 '22 04:10

Linga