Adjust EditText icon away from the left border - android

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"
/>

Related

How to add drawablePadding only for one side

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"

layout_alignBottom aligns center instead of bottom

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

Android: Space between image and text inside edit text

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.

How to match drawableleft borders with its parent edittext's borders?

I am trying to add a drawableleft to an Edittext:
<EditText
android:id="#+id/editUserName"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:drawableLeft="#drawable/icon_email"
android:hint="#string/login_identity_hint"
android:textSize="12sp" />
Here is how it looks like:
As you see, the image does not match its parent's borders, there is padding from left, bottom and top even though i do not set any padding. What can i do about it?
I also tried the following approach:
<RelativeLayout
android:id="#+id/editUserNameContainer"
android:layout_width="match_parent"
android:layout_height="wrap_content" >
<ImageView android:id="#+id/img"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:background="#drawable/icon_email"
android:layout_alignParentLeft="true"/>
<EditText
android:layout_toRightOf="#+id/img"
android:id="#+id/editUserName"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:drawablePadding="5dp"
android:hint="hint"
android:textSize="12sp" />
</RelativeLayout>
But this time, it looks like the following: The image and edittext's heights do not match and there is a small gap between them:
Thanks.
I am thinking the only way you can get it to be how you want is to do something like this....
Remove android:drawablePadding="5dp" from EditText
Remove android:layout_toRightOf="#+id/img" from EditText
Add android:paddingLeft="50dp" to EditText
Add android:layout_alignParentLeft="true" to ImageView
This will just put the image over the top of your edit text, and using the padding to move the text in the edit text box to the right a bit after the image. You may need to make adjustments to the image view to make it fit just right
Let me know how this works!
<ImageView android:id="#+id/img"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:background="#drawable/icon_email"
android:layout_alignParentLeft="true"/>
<EditText
android:layout_alignParentLeft="true"
android:id="#+id/editUserName"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:paddingLeft="50dp"
android:hint="hint"
android:textSize="12sp" />

Android EditText not expanding when hitting enter

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"

Categories

Resources