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 ?
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 ;))
Use this
android:singleLine="true"
instead of,
android:lines="1"
android:maxLines="1"
Change,
android:inputType="none"
to
android:inputType="text" or android:inputType="number"
according to your requirement.
use this code :
<EditText
android:id="@+id/Et_loginEmail"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="@drawable/layout_bg"
android:hint="Email Address"
android:singleLine="true"
android:ellipsize="end"
/>
This alone is enough to make single line in EditText.
<EditText
android:id="@+id/fullname"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:hint="Full Name"
android:inputType="text"/>
android:inputType="text"
alone solves the single line in EditText
.
You need to choose your desired inputType
as per your requirement.
change the android:inputType="none"
<EditText
android:id="@+id/txtSearch"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginLeft="5dp"
android:drawablePadding="5dp"
android:maxLines="1"
android:inputType="none"
android:scrollHorizontally="true"
android:paddingLeft="5dp"
android:textSize="12sp" />
to
<EditText
android:id="@+id/txtSearch"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginLeft="5dp"
android:drawablePadding="5dp"
android:maxLines="1"
android:inputType="text"
android:scrollHorizontally="true"
android:paddingLeft="5dp"
android:textSize="12sp" />
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.