Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to align EditText cursor properly?

I have an edit text with a 200sp size. The cursor appears in the middle. How can I make sure the cursor appears in the left corner? It looks odd being in the center.

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:orientation="vertical"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent"
    >
    <EditText android:layout_width="match_parent" android:layout_height="wrap_content" android:id="@+id/composeEditText" android:minHeight="200sp" android:focusable="true" android:hint="Share an idea with the community"></EditText>
    <LinearLayout android:layout_width="match_parent" android:layout_height="wrap_content" android:id="@+id/toolbarLinearLayout">
        <Button android:layout_width="wrap_content" android:layout_height="wrap_content" android:id="@+id/sendButton" android:text="Send"></Button>
        <Button android:layout_width="wrap_content" android:layout_height="wrap_content" android:id="@+id/shortenButton" android:text="Shorten"></Button>
        <TextView android:layout_width="wrap_content" android:layout_height="wrap_content" android:id="@+id/charCountTextView" android:text="140"></TextView>
    </LinearLayout>

</LinearLayout>
like image 296
Sheehan Alam Avatar asked May 23 '11 16:05

Sheehan Alam


People also ask

How do I change the cursor position in EditText?

Say in your xml's edittext section, add android:paddingLeft="100dp" This will move your start position of cursor 100dp right from left end. Same way, you can use android:paddingRight="100dp" This will move your end position of cursor 100dp left from right end.

How do you center text in EditText?

Simpler Solution to align text in EditText is to add android:gravity="center" in layout xml. There is no need to add Java code.


2 Answers

Use android:gravity="top|left"

http://developer.android.com/reference/android/widget/TextView.html#attr_android:gravity

like image 97
Aleadam Avatar answered Sep 19 '22 12:09

Aleadam


You should use gravity attribute:

<EditText android:gravity="left|bottom" ... />
like image 37
inazaruk Avatar answered Sep 18 '22 12:09

inazaruk