restrict edittext to single line
Use android:maxLines="1"
and android:inputType="text"
You forgot the android:maxLines attribute. And refer for android:inputType With your example, below will give this result:
<EditText
android:id="@+id/searchbox"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:maxLines="1"
android:inputType="text"
android:scrollHorizontally="true"
android:ellipsize="end"
android:layout_weight="1"
android:layout_marginTop="2dp"
android:drawablePadding="10dp"
android:background="@drawable/edittext"
android:drawableLeft="@drawable/folder_full"
android:drawableRight="@drawable/search"
android:paddingLeft="15dp"
android:hint="search...">
</EditText>
EditText won't write into single line
I think this will work for you. Let me know if it works.
<EditText
android:id="@+id/textView"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_gravity="end"
android:background="@color/colorBlue"
android:textAlignment="textEnd"
android:textSize="40sp"
android:inputType="text"
android:maxLines="1"
android:lines="1"
android:scrollHorizontally="true"
android:ellipsize="end"/>
This post might help you as well.
Disable Enter in editText android
Because of different Android versions, the best practice is to include these parameters at the same time:
android:maxLines="1"
android:lines="1"
android:singleLine="true"
If you don't, it will not work correctly on some devices.
Edittext View One line
<EditText
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:hint="Full Name"
android:scrollHorizontally="false"
android:id="@+id/textView_data2"
android:textSize="20sp"
android:layout_marginTop="10dp"
android:layout_marginBottom="10dp"
android:maxLines="1"
android:inputType="textPersonName"
android:gravity="fill_vertical" />
Unable to make EditText multi-line
Okay so, I knew that the problem arises when I click on the edit button. Clicking the button made the editText single lined automatically even though I had mentioned the InputType as Multi-line in XML very clearly.
What I did to make the editText multi-line after the button click is that I wrote editTextContent.setSingleLine(false);
in my java file inside the onClick button code.
And that is it. :)
Prevent EditText from going to new line when 'Space' is tapped
You can Add Two Hidden Spaces Before \n's.
To add a Hidden space: Alt + 0160 (Numpad keys).
So, When User is typing something, The Hidden Spaces will keep moving and UserText won't be able to reach to \n.
Related Topics
Classloader Referenced Unknown Path: /Data/App/
How Does One Use Basic Authentication with Volley on Android
Change Keyboard Input Language
How to Ask Runtime Permissions for Camera in Android , Runtime Storage Permissions
How to Pause Frame Animation Using Animationdrawable
Android, Move Bitmap Along a Path
Android Java.Lang.Illegalstateexception: Couldn't Read Row 0, Col 0 from Cursorwindow
Error Inflating Class and Android.Support.V7.Widget.Cardview
How to Programmatically Get the List of Registered Users in Firebase
Should One Create a Bond with a Bluetooth Le Device
How to Disable Facebook Single Sign on for Android - Facebook-Android-Sdk
Replacing Default Phone App on Android 6 and 7 with Incallservice
Android Studio: Gradle: Error: Cannot Find Symbol Variable
Android: Permission Denial: Starting Intent with Revoked Permission Android.Permission.Camera
Android Gridview Row Dividers/Separators