Is there any way to add drawablePadding only right not for all
<EditText
android:hint="Contact number"
android:layout_weight="1"
android:drawablePadding="2dp"
android:id="#+id/et_mobile_number"
android:drawableStart="#drawable/ic_mobile"
android:layout_width="match_parent"
android:layout_height="wrap_content">
</EditText>
Like this android:paddingRight="" for drawable image
can you please try to add this line to your edittext and check whether it solve your issue.
android:drawableStart="#drawable/ic_mobile"
android:drawableLeft="#drawable/ic_mobile"
android:drawablePadding="10dp"
Related
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"
/>
I'm trying to get the bottom of my TextView and EditText to line up (perhaps not to the pixel, but close) inside of a RelativeLayout. But layout_alignBottom seems to line up their center line instead of their bottom:
I tried layout_alignBaseline also, but the result was that the EditText does not display on the screen. I also made various efforts at adjusting padding, but it didn't change anything. This seems like it should be easy and a common issue, but I couldn't find anything Googling. Any help would be greatly appreciated.
Thanks.
<TextView
android:id="#+id/firstNameLabel"
android:layout_marginTop="20dp"
android:layout_marginRight="24dp"
android:layout_alignParentLeft="true"
android:layout_alignParentTop="true"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="First Name" />
<EditText
android:layout_toRightOf="#+id/firstNameLabel"
android:layout_alignBottom="#+id/firstNameLabel"
android:id="#+id/firstName"
android:layout_width="match_parent"
android:layout_height="wrap_content"
/>
Try this.
<RelativeLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content">
<TextView
android:id="#+id/firstNameLabel"
android:layout_marginRight="24dp"
android:layout_alignParentBottom="true"
android:layout_alignParentLeft="true"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerVertical="true"
android:text="First Name"
android:textSize="20sp"/>
<EditText
android:layout_toRightOf="#+id/firstNameLabel"
android:layout_alignParentBottom="true"
android:id="#+id/firstName"
android:hint="YO BABY"
android:layout_centerVertical="true"
android:layout_width="match_parent"
android:layout_height="wrap_content"/>
</RelativeLayout>
Hope this helps.
Remove margin top from code and check
What's causing this is the EditText being bigger than the textview. Check your layout that contains both and set the gravity to "center" or "center_vertical".
Edit: If you're using RelativeLayout, you should probably use "layout_centerVertical" or "layout_centerInParent" instead
I have a EditText in my app and i would like to align the text in it a bit more to the right is there a would to do this by axml?
To move your text to right side in your editText,you can use gravity and padding.
Check this here:
<EditText
android:id="#+id/edt_email"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:ems="10"
android:paddingLeft="10dp"
android:text="Test"
android:hint="Email"
android:singleLine="true"
android:textSize="18sp" />
Try adding android:gravity="right" to the EditText
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"
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