I have a multiline edittext with maxLines as 1. When the input exceeds more than one line, the previous lines entered shift by few pixels to top as shown in image 1 below.
How can i center vertical each line in edittext?
<EditText android:id="#+id/et"
android:layout_width="match_parent"
android:layout_height="30dp"
android:layout_marginTop="50dp"
android:paddingStart="10dp"
android:paddingEnd="10dp"
android:maxLines="1"
android:inputType="textMultiLine|textNoSuggestions"/>
I figured it out:
You've set android:layout_height="30dp" and depending on the user phone's font size or your own app's it will show just part of it or have extra room like you had in your first picture:
change the EditText to:
<EditText
android:id="#+id/et"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="50dp"
android:paddingStart="10dp"
android:paddingEnd="10dp"
android:maxLines="1"
android:inputType="textMultiLine|textNoSuggestions"
/>
I've tested it and worked fine, but let me know if it's not working for you.
Related
I have a EditText, where the text is in the middle of the EditText(gravity:center)
But when a line break happens, the text starts from the middle under the text. What I want is that the text shall start from the left when a linebreak happens.
This picture explains what I want to archive: http://oi61.tinypic.com/zycxut.jpg
I have tried all theese: Text-align:Viewstart/textStart, Gravity: Center | left
without any succses.
<EditText
android:id="#+id/edittext"
android:textColor="#000000"
android:background="#ffffff"
android:layout_width="match_parent"
android:layout_height="320dp"
android:editable="true"
android:layout_below="#id/toolbar"
android:layout_marginTop="44dp"
android:singleLine="false"
android:gravity="center"/>
try this,
you can add android:inputType="textMultiLine"
<EditText
android:id="#+id/edittext"
android:layout_width="match_parent"
android:layout_height="320dp"
android:layout_marginTop="44dp"
android:background="#ffffff"
android:editable="true"
android:gravity="center"
android:inputType="textMultiLine"
android:textColor="#000000" />
OK, so by the looks of your picture, it seems that you want the text left justified and starting in the middle of the EditText. There isn't a way to do this directly, but we can make a work around by using 2 EditTexts, each taking up half of the white block in your image, then ignoring the one on the left. This will give the appearance of text starting from the middle, when in reality it starts from the left edge of the right EditText.
<LinearLayout
android:layout_width="fill_parent"
android:layout_height="320dp"
android:weightSum="2"
android:orientation="horizontal">
<EditText
android:id="#+id/ignore_this_one"
android:layout_width="0dp"
android:layout_height="fill_parent"
android:layout_weight="1"
android:background="#ffffff"
android:editable="false" />
<EditText
android:id="#+id/put_text_in_here"
android:layout_width="0dp"
android:layout_height="fill_parent"
android:layout_weight="1"
android:background="#ffffff"
android:editable="true"
android:gravity="center_vertical"
android:inputType="textMultiLine"
android:textColor="#000000" />
</LinearLayout>
First, notice how each EditText has a layout_weight of 1. This tells Android that they should each take up an equal amount of space on the screen, making them each take up half.
Second, notice how the second EditText has a gravity_vertical element. This makes it so text is centered vertically, but not horizontally.
As the title said, I want to put a little bit of space between the lock icon and the text.
And here is my current XML:
<EditText
android:id="#+id/guide_payment_settings_email_et"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginLeft="7dp"
android:layout_marginRight="7dp"
android:layout_marginTop="5dp"
android:background="#drawable/border_paylpal_blue"
android:drawableLeft="#drawable/blue_rounded_lock"
android:hint="name#example.com"
android:inputType="textEmailAddress"
android:singleLine="true"
android:textColor="#4d4e5b"
android:textSize="12sp" />
You have to add below line on your xml :-
android:drawablePadding="10dp"
above line give padding after drawable.
I have problem regarding Edit-text in android . I am setting a background of Edit-text and its width is "wrap_content" as below in my code.But when user enter a large text in it the size of the background is exceeded to its actual size
<EditText
android:id="#+id/edtEmail"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="15dp"
android:background="#drawable/text_field"
android:hint="#string/email_address"
android:inputType="textEmailAddress"
android:paddingEnd="20dp"
android:paddingLeft="10dp"
android:paddingRight="10dp"
android:scrollHorizontally="true"
android:singleLine="true" />
So my I want it to be scroll able horizontally after 30 character .So that I don't exceed its actual size of background .Any help will be appreciable .
Thanks in advance
try setting this property
android:maxEms="4"
example: this is my edittext
<EditText
android:id="#+id/edittext_email_address"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="5dp"
android:background="#drawable/bg_gray_edittext"
android:gravity="center"
android:hint="#string/hint_email_address"
android:imeOptions="actionNext"
android:inputType="textEmailAddress"
android:padding="5dp"
android:text="abcdefghijklmnopqrstuvwxyz1234567890qwerty1235"
android:textColor="#color/white"
android:maxEms="4"
android:textColorHint="#color/white70"
android:textSize="20sp" />
hope this works
Set this property to your Edittext and it'll scroll after the number of characters exceed the width.
android:singleLine="true"
i am usign adjustpan in activity it's scroll perfect when simple Edit text with single line but, it's not work properly in multiline edittext with height mentioned like below ediitext xml layout
<EditText
android:id="#+id/txt_feedback"
android:layout_width="400dp"
android:layout_height="wrap_content"
android:layout_alignLeft="#+id/txt_to"
android:layout_alignRight="#+id/txt_to"
android:ems="10"
android:gravity="top|left"
android:inputType="textMultiLine"
android:lines="8"
android:maxLength="160"
android:minLines="6"
android:scrollbars="vertical"
android:background="#drawable/textboxborder"
android:padding="2dp"
android:singleLine="false"
android:layout_marginTop="5dp"
android:visibility="gone"
android:hint="-- Your Comments --"
android:layout_marginLeft="40dp" />
for current output below like screen:
and i am excepted output like below screen:
and how to do this somebody help me ?
Thanks :)
I want to make a multi line edit text but the problem is that whenever i enter new line height of edit text increases. how to fix its height. My code is
<EditText
android:id="#+id/editAdditionalInfo"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignLeft="#+id/editPhoneCutomerDetails"
android:layout_alignParentBottom="true"
android:layout_marginBottom="60dp"
android:layout_below="#+id/editPhoneCutomerDetails"
android:layout_marginTop="10dp"
android:background="#drawable/message_additional_box1x"
android:ems="10"
android:padding="10dp"
android:gravity="top">
<requestFocus />
</EditText>
To fix the size of editText you can use
android:singleLine="true"
but it can limit your editText line to 1 .
if you want more lines in editText then use the following property.
Use android:lines="3" .
Use android:lines="2" for fixing multilines and for fixing single line use android:singleLine="true"
for example use like this as shown for multilines
<EditText
android:id="#+id/.."
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_weight="1"
android:background="#android:drawable/editbox_background_normal"
android:ems="10"
android:hint="Name"
android:maxLength="20"
android:lines="2"// fix the multiline limit
android:textColor="#000000" />
for example use like this as shown for single line
<EditText
android:id="#+id/.."
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_weight="1"
android:background="#android:drawable/editbox_background_normal"
android:ems="10"
android:hint="Name"
android:maxLength="20"
android:singleLine="true"// fix the single line limit
android:textColor="#000000" />
try this;
android:inputType="textMultiLine"
<EditText
android:inputType="textMultiLine"
android:layout_width="wrap_content"
android:layout_height="wrap_content"/>
As singleline is now deprecated use inputType:multiline and set the number of lines you want with lines tag
<EditText
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:inputType="textMultiLine"
android:lines="4"/>
I had a similar requirement but ended up not changing the size of the box. i.e it grows as text is typed into it but stops short of blocking the other widgets in view. I read this post during my quest and had found a solution. Decided to post it back here. Restricting size to a value may possibly have different effects on different screens. So I think it is better to let it be.
The thing is to put the edit text inside a linearlayout with the rest of the widgets. The code and snapshot are here
Multi line edit box with ok cancel buttons