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>
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.
Simpler Solution to align text in EditText is to add android:gravity="center" in layout xml. There is no need to add Java code.
Use android:gravity="top|left"
http://developer.android.com/reference/android/widget/TextView.html#attr_android:gravity
You should use gravity
attribute:
<EditText android:gravity="left|bottom" ... />
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With