In my application i have a an EditText that is aligned to the left.
I would like the text in that EditText to be a bit more to the right by like 5dp or some other form of measurement that is not "left" or "center".
How to do that?
Thank you.
Use padding in EditText
<EditText
android:id="#+id/editText"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:paddingLeft="5dp"
android:gravity="left"/>
Related
Having fiddled with this for longer than I care to admit, how does text alignment work within a TextView?
Obviously I'm trying to get the 'N' to centre itself vertically in the TextView.
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="#string/titleN"
android:id="#+id/textView"
android:height="114dp"
android:textSize="120dp"
android:layout_alignParentTop="true"
android:layout_alignParentLeft="true"
android:layout_alignParentStart="true"
android:layout_alignBottom="#+id/textView3"
android:layout_gravity="center"
android:gravity="center"/>
When I remove height it looks like:
The problem is that the TextView's height(114dp) is smaller than the size of the text (120dp) itself, remove the height attribute from the TextView, you don't need this line
android:height="114dp" // you need to remove this attribute from the TextView
What you need is android:gravity="center_vertical"
when the gravity of the textview is set for center_vertical text will remain in the center irrespective of the textView's height
Example:-
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:gravity="center_vertical"
android:text="N"
android:textAppearance="?android:attr/textAppearanceLarge" />
Output
as per #Keshav's link to https://stackoverflow.com/a/6594320/2346980, setting android:layout_marginTop to a negative value corrected the text position inside TextView.
Try using maring attributes, like margin-top or margin-bottom. If that doesnt work try using padding, like padding-top or padding-bottom
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"
There is EditText pictured on the left.
How to make text inside EditText and drawableRight to have padding as on the right?
The EditText has rounded corners, see android:background,
however there is no interval set from EditText left edge to text start and from drawableRight to the EditText right edge.
<EditText
android:id="#+id/search_editbox"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_centerVertical="true"
android:layout_gravity="center_vertical"
android:layout_toLeftOf="#id/search_execute_imageview"
android:layout_toRightOf="#id/layout_back_logo"
android:background="#drawable/rounded_edittext_states"
android:drawableRight="#drawable/abc_ic_clear_holo_light"
android:gravity="left|center_vertical"
android:hint="#string/search_hint"
android:maxLength="20"
android:padding="5dip"
android:singleLine="true"
android:textCursorDrawable="#null"
android:textSize="#dimen/main_text_size" />
I tried
android:paddingLeft="30dp"
android:paddingRight="30dp"
but it had no result.
Try this, it will work-
android:drawablePadding="30dp" for interval between drawable and text.
Edit: actually remove padding and paddingLeft and paddingRight
I have a very big text field but writing on it is not as I'd like. Is there a way I can move cursor to the top left of the field (so that it looks like a text area). Because by default it is centered. Thanks a lot
I use:
<EditText
android:layout_width="400dp"
android:layout_height="500dp"
android:id="#+id/editText"
android:layout_alignParentTop="true"
android:layout_centerHorizontal="true" />
Add android:gravity attribute to EditText with value top|left.
android:gravity="top|left"
I have an EditText with the property:
android:minLines="3"
However, when I start typing, it types in the middle of the EditText.
Is there any way to get this to start typing at the top left of the EditText area?
Add android:gravity="top|left" to the EditText in the layout XML file.
Just insert
android:gravity="top"
into your EditText.
android:gravity="start" would put it to the top left.
This will help you. Try this EditText....
<EditText
android:id="#+id/edt_comment_note"
android:layout_width="fill_parent"
android:layout_height="60dp"
android:background="#drawable/white_box"
android:gravity="top"
android:hint="Note"
android:imeOptions="actionDone"
android:maxLines="3"
android:padding="5dp"
android:textSize="15sp" />