Home > OS >  Make Edit text scrollable after specific lines
Make Edit text scrollable after specific lines

Time:10-07

I am designing chat UI. My requirement is to make edit Text scrollable after 6 lines like in happens in Whatsapp.

Here is my code

 <androidx.constraintlayout.widget.ConstraintLayout
        android:id="@ id/downLayout"
        android:layout_width="0dp"
        android:layout_height="@dimen/_40sdp"
        android:layout_marginStart="@dimen/_20sdp"
        android:layout_marginEnd="@dimen/_20sdp"
        android:layout_marginBottom="@dimen/_10sdp"
        android:background="@drawable/layout_background"
        app:layout_constraintBottom_toBottomOf="parent"
        app:layout_constraintEnd_toEndOf="parent"
        app:layout_constraintStart_toStartOf="parent">




        <EditText
            android:id="@ id/etTypeMessage"
            style="@style/noteText.Black"
            android:layout_width="0dp"
            android:layout_height="wrap_content"
            android:layout_margin="@dimen/_16sdp"
            android:background="@null"
            android:hint="Type a message"
            android:scrollbars="vertical"
            android:textColorHint="@color/black"
            android:textColorHighlight="@color/duck_egg_blue"
            app:layout_constraintBottom_toBottomOf="parent"
            app:layout_constraintEnd_toStartOf="@ id/ivAttachments"
            app:layout_constraintStart_toStartOf="parent"
            app:layout_constraintTop_toTopOf="parent"

            />



        <ImageView
            android:id="@ id/ivSend"
            android:layout_width="22dp"
            android:layout_height="22dp"
            android:layout_marginTop="16dp"
            android:layout_marginEnd="16dp"
            android:layout_marginBottom="16dp"
            android:src="@drawable/ic_send"
            app:layout_constraintBottom_toBottomOf="parent"
            app:layout_constraintEnd_toEndOf="parent"
            app:layout_constraintTop_toTopOf="parent" />


        <ImageView
            android:id="@ id/ivAttachments"
            android:layout_width="22dp"
            android:layout_height="22dp"
            android:layout_marginTop="16dp"
            android:layout_marginEnd="16dp"
            android:layout_marginBottom="16dp"
            android:src="@drawable/ic_attachment"
            app:layout_constraintBottom_toBottomOf="@ id/ivSend"
            app:layout_constraintEnd_toStartOf="@ id/ivSend"
            app:layout_constraintTop_toTopOf="@ id/ivSend" />




    </androidx.constraintlayout.widget.ConstraintLayout>

The goal is to create UI like WhatsApp. As soon as user enters to next line edittext expands and after 6 lines edittext becomes scrollable. The goal is to make UI like this.

CodePudding user response:

Add the below lines

android:scrollbars="vertical"
android:maxLines="6"
android:inputType="textMultiLine"
  • Related