Android EditText not expanding when hitting enter - android

I have a EditText look like this in my layout xml and it's not expanding when the user hit enter
<EditText
android:layout_height="40dp"
android:layout_width="fill_parent"
android:gravity="top"
android:maxLines="10"
android:minHeight="40dp"
android:id="#+id/edSearch"
android:layout_toLeftOf="#+id/btnSearch"
android:layout_centerVertical="true"
android:layout_alignParentLeft="true"
android:hint="City..."
/>
but when i changed android:layout_height="40dp" to android:layout_height="wrap_content" the the edittext is able to expand as the user hit enter.
how I can keep my EditText expanding while keeping this line android:layout_height="40dp"
Thanks

Try this
<EditText
android:layout_height="wrap_content"
android:layout_width="match_parent"
android:gravity="Top"
android:maxLines="10"
android:minHeight="40dp"
android:id="#+id/edSearch"
android:layout_toLeftOf="#+id/btnSearch"
android:layout_centerVertical="true"
android:layout_alignParentLeft="true"
android:inputType="textMultiLine"
android:hint="City..."
/>
Hope this will work

I'm using following code and it's working great. to set minimum height instead of setting layout_height to 40dp set it wrap_content and set attribute of minLines to achieve this as show below in code example
<EditText
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:ems="10"
android:inputType="textMultiLine"
android:minLines="4"
android:maxLines="10"
/>

Set property android:multiline="true".
hope this will help you.

Set android:multiline="true" along with android:gravity="left|top"

Related

android 8.0 EditText hint content is not in the middle

When the EditText not gets the focus, the hint content is not in the middle. Why is this happening? Who can help me?
Less than 7.0 its ok
in the 7.1 8.0 it unable to display normally
this is my xml code
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="90px">
<View
android:layout_width="match_parent"
android:layout_height="1px"
android:layout_alignParentBottom="true"
android:layout_marginLeft="30px"
android:background="#color/c_dbdbdb"/>
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerVertical="true"
android:layout_marginLeft="30px"
android:text="年龄"
android:textColor="#color/c_666666"
android:textSize="32px"/>
<EditText
android:id="#+id/et_new_appointment_age"
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:layout_marginLeft="230px"
android:background="#null"
android:gravity="center_vertical"
android:hint="请输入年龄"
android:inputType="number"
android:minWidth="200px"
android:textColor="#color/c_333333"
android:textColorHint="#color/c_999999"
android:textSize="32px"/>
</RelativeLayout>
Define your edit text ellipsize as start and try I think it will help you.
android:ellipsize="start"
put editText with width and height as wrap content and use
android:layout_centerVertical="true"
android:layout_centerHorizontal="true"
inside edit text. it will work.

Adjust EditText icon away from the left border

I created an EditText with a drawable image. The problem is that the image is very close to the border of the EditText, is there a way to adjust it?
Note: Im using an svg file for the image
Image: In the image you can see the shoulder of the person is almost touching the left border
Code:
<EditText
android:id="#+id/sampleName"
android:drawableStart="#drawable/sampleImage"
android:drawablePadding="10dp"
android:layout_height="wrap_content"
android:maxLines="1"
android:layout_width="match_parent"
android:background="#color/white"
android:layout_marginLeft="5dp"
/>
You can try android:padding to the EditText along with the android:drawablePadding
Just add android:padding="5dp" . It will work .
Removing Below Line from your code will solve the problem :
android:layout_marginLeft="5dp"
You can use drawablePadding and paddingto give space to the image. Try it like this:
<EditText
android:id="#+id/sampleName"
android:drawableStart="#drawable/sampleImage"
android:drawablePadding="10dp"
android:layout_height="wrap_content"
android:maxLines="1"
android:layout_width="match_parent"
android:background="#color/white"
android:drawablePadding="5dp"
android:padding="5dp"
android:layout_marginLeft="5dp"
/>
Try this
<EditText
android:id="#+id/sampleName"
android:drawableStart="#drawable/sampleImage"
android:drawablePadding="10dp"
android:layout_height="wrap_content"
android:maxLines="1"
android:layout_width="match_parent"
android:background="#color/white"
android:padding="15dp"
android:layout_marginLeft="5dp"
/>

EditText won't write into single line

I'm making a calculator and user input is contained in EditText. Input is typed through buttons on screen, so Android keyboard is disabled. However, I want it to write all input in one line and when line reaches border, it needs to be ellipsized and then horizontally scrollable so you can reach whole text.
I tried doing this by setting android:maxLines="1" and android:ellipsize="end", but that doesn't work. Text is still in multiple lines, but only one line is visible and you need to scroll vertically to see other lines. I also tried using android:singleLine="true", but that makes EditText completely unusable.
This is EditText XML:
<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" />
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.
For single line in EditText, you just need to set two properties:
android:inputType="text"
android:maxLines="1"
Adding this line in the edittext make scrollable singleline text.
android:inputType="textShortMessage"
**This example helps you to create multiline EditText in Android.**
<RelativeLayout
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:id="#+id/rl"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:padding="10dp"
tools:context=".MainActivity"
>
<!--
android:scrollbars="vertical"
It will display a vertical scrollbar if the EditText text exceed
3 lines (android:maxLines).
-->
<EditText
android:id="#+id/et"
android:layout_width="250dp"
android:layout_height="wrap_content"
android:padding="10dp"
android:layout_marginBottom="10dp"
android:hint="Multiline EditText by XML layout"
android:fontFamily="sans-serif-condensed"
android:background="#d3d7b6"
android:minLines="2"
android:maxLines="3"
android:scrollbars="vertical"
android:inputType="textMultiLine"
/>
<EditText
android:id="#+id/et2"
android:layout_width="250dp"
android:layout_height="wrap_content"
android:padding="10dp"
android:fontFamily="sans-serif-condensed"
android:hint="Multiline EditText programmatically"
android:background="#d4d7a5"
android:layout_below="#+id/et"
/>
</RelativeLayout>

My Edittext getting extended while typing the text

My Edittext its getting extend automatically while typing the text,Dont know what mistake i have done, please check my screen shot for exactly what my issue is, help me to find a solution. Thanks in advance.
<LinearLayout
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_marginTop="50dip"
android:gravity="center"
android:orientation="vertical" >
<LinearLayout
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:gravity="center" >
<EditText
android:id="#+id/oldpass"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:background="#drawable/selectdate"
android:ems="10"
android:hint="#string/oldpass"
android:inputType="textPassword"
android:paddingLeft="5dip" >
</EditText>
</LinearLayout>
</LinearLayout>
check my screen shot for how its extend while typing
your height and weight are Wrap_content as it adjust upon the length of the text you given
change that to fixed dp length
android:layout_width="150dp"
android:layout_height="wrap_content"
It is due to this layout definition: android:layout_width="wrap_content"
You're basically telling that your EditText should fit the content. That means it will have a default size, but once you're typing in it and making it wider, it will extend according to the text it has inside.
You probably want to use android:layout_width="match_parent" to fit it to the screen, or play around with android:layout_weight to make it proportional to other layout items.
Set WEIGHT property of your edittext it will not extended.
android:layout_width="0dp"
android:layout_weight="1"
Try this
<LinearLayout
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_marginLeft="10dp"
android:layout_marginRight="10dp"
android:gravity="center" >
<EditText
android:id="#+id/oldpass"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:background="#drawable/selectdate"
android:ems="10"
android:hint="#string/oldpass"
android:inputType="textPassword"
android:paddingLeft="5dip" >
</EditText>
</LinearLayout>
I believe your issue is you are setting the layout_width of the EditText as wrap_content

Android: Vertical alignment for multi line EditText (Text area)

I want to have 5 lines for the height of the text area. I am using the following code.
<EditText
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:gravity="center"
android:singleLine="false"
android:lines="5"
android:layout_marginLeft="10dip"
android:layout_marginRight="10dip" />
The text area looks fine, but the problem is that the cursor is blinking in the middle of the text field. I want it to blink at first line, at the first character of the text field.
Use android:gravity="top"
This is similar to CommonsWare answer but with a minor tweak: android:gravity="top|start". Complete code example:
<EditText
android:id="#+id/EditText02"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:lines="5"
android:gravity="top|start"
android:inputType="textMultiLine"
android:scrollHorizontally="false"
/>
U can use this Edittext....This will help you.
<EditText
android:id="#+id/EditText02"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:lines="5"
android:gravity="top|left"
android:inputType="textMultiLine" />
Use this:
android:gravity="top"
or
android:gravity="top|left"
<EditText android:id="#+id/EditText02" android:layout_width="120dp"
android:layout_height="wrap_content" android:lines="5" android:layout_centerInParent="true"
android:gravity="top|left" android:inputType="textMultiLine"
android:scrollHorizontally="false" android:minWidth="10.0dip"
android:maxWidth="180dip" />
it will work
Now a day use of gravity start is best choise:
android:gravity="start"
For EditText (textarea):
<EditText
android:id="#+id/EditText02"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:lines="5"
android:gravity="start"
android:inputType="textMultiLine"
/>
I think you can use layout:weight = 5 instead android:lines = 5 because when you port your app to smaller device - it does it nicely.. well, both attributes will accomplish your job..

Categories

Resources