Viktor
Viktor

Reputation: 646

How to put cursor into the start of edittext instead of middle of the whole edittext?

I have EditText which takes up the entire screen. And cursor is always in the middle of EditText, but I need it to be at the top of EditText. What am I supposed to do? My layout:

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:orientation="vertical">

    <EditText
        android:id="@+id/noteEditText"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:layout_alignParentTop="true"
        android:background="@null"
        android:inputType="textLongMessage|textCapSentences|textImeMultiLine|textMultiLine" />

</RelativeLayout>

Upvotes: 1

Views: 64

Answers (2)

Vishnu
Vishnu

Reputation: 785

Try adding android:gravity="start|top" & android:textAlignment="viewStart"

Here' the full code

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:orientation="vertical">

    <EditText
        android:id="@+id/noteEditText"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:layout_alignParentTop="true"
        android:background="@null"
        android:gravity="start|top"
        android:inputType="textLongMessage|textCapSentences|textImeMultiLine|textMultiLine"
        android:textAlignment="viewStart" />

</RelativeLayout>

Hope this helps. Feel free to ask for clarifications

Upvotes: 2

Yunus Karaaslan
Yunus Karaaslan

Reputation: 304

Add this line to your EditText.

android:gravity="top|left"

Upvotes: 2

Related Questions