I have taken an EditText as follows :
<EditText
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:hint="This is text"
android:drawableLeft="#drawable/search"
android:layout_centerInParent="true"/>
What if I want to set some spaces between that drawable icon and hint of EditText ?
For this use the attribute drawablePadding. This adds some padding between text and image.
Use android:drawablePadding property.
eg. android:drawablePadding="5dp"
Try this
<EditText
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:hint="This is text"
android:drawableLeft="#drawable/search"
android:layout_centerInParent="true"
android:drawablePadding="10dp" />
Add These Two Lines Of Code And you are good to go your icon will not touch the border of EditText and your icon and hint has some space in between As you can see in the pictures below
<EditText
android:drawablePadding="10dp"
android:paddingLeft="15dp"/>
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 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 want to make drawable and text center in my EditText. The text is centered but the drawable is not. I want something like this:
http://i.imgur.com/cacxR2C.jpg?1
Please help. This is what I have done so far
<EditText
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:hint="Username"
android:layout_marginLeft="15dp"
android:layout_marginRight="15dp"
android:gravity="center_horizontal"
android:drawableLeft="#drawable/lol2"
/>
When the user types in something in the EditText, the drawable should move itself to the left if the text is lenghty.
You can do something like this
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:gravity="center"
android:layout_marginLeft="15dp"
android:layout_marginRight="15dp"
android:background="#android:drawable/editbox_background"
>
<EditText
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:hint="Username"
android:background="#null"
android:gravity="center"
android:drawableLeft="#drawable/ic_launcher"
/>
</RelativeLayout>
This worked for me:
<EditText
android:id="#+id/searchET"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:paddingStart="75dp"
android:paddingEnd="75dp"
android:inputType="text"
android:singleLine="true"
android:gravity="center"
android:hint=" Username"
android:drawableStart="#drawable/your_icon"
android:background="#android:drawable/editbox_background"/>
The kicker here is that you wrap_content for the width, align the text however, center the view however you'd like, then add padding to each end of the edit text.
This shoves the drawable to the start of your text but still lets you expand your edit text background.
instead of
android:drawableLeft="#drawable/lol2"
try using
android:drawableStart="#drawable/lol2"
Basically gravity attribute is used to apply changes of aligning the contents of lay out so you can put the gravity to center to align contents in center and center_vertical to to align contents on left side and gravity to center_horizontal to put contents in horizontal center. i.e
android:gravity="center"
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.
Hello I am setting drawable to left end in the EditText using property android:drawableLeft="#drawable/email_drawable", I am trying this it set the drawable perfectly but it is not setting gap between left drawable and text. Could you please help me to achieve this ?
<EditText
android:id="#+id/emailEditText"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="#dimen/sign_up_edittext_vertical_top_margin"
android:drawableLeft="#drawable/email_drawable"
android:imeOptions="actionNext"
android:inputType="textEmailAddress"
android:singleLine="true" />
You should add android:drawablePadding attribute to your EditText. Example layout with 10dp drawable padding:
<EditText
android:id="#+id/emailEditText"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="#dimen/sign_up_edittext_vertical_top_margin"
android:drawableLeft="#drawable/email_drawable"
android:imeOptions="actionNext"
android:inputType="textEmailAddress"
android:drawablePadding="10dp"
android:singleLine="true" />
to move the drawable icon left or right use android:paddingLeft or android:paddingRight do not use android:drawablePadding
When you set any drawable using android:drawableLeft / android:drawableRight property then you can add space or gap using android:drawablePadding property.
<EditText
android:id="#+id/emailEditText"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="#dimen/sign_up_edittext_vertical_top_margin"
android:drawableLeft="#drawable/email_drawable"
android:imeOptions="actionNext"
android:drawablePadding="5dp" // set your padding or gap size here
android:inputType="textEmailAddress"
android:singleLine="true" />