ojbqa
ojbqa

Reputation: 27

I've been trying to add text wrap to my edittext, and nothing looks right

Ok, let me give you some context. I'm making a messaging application (you can tell from my other posts) and right now I'm working on a function to edit your messages. The dialog that shows up has an enter button, but my message box doesn't, it has a "Done" button. I set the imeOptions of that text box to have an enter button and configured some other properties to make it work.

But for some reason, nothing looks polished. I've tried looking at other StackOverflow posts, looking at Google, changing my drawables (which I use for the background of my edittext) but it doesn't look as I expected. I expect the edittext to be at a fixed height once the message box reaches 4 or so lines, and for the attachment icon to always stay in the same location, not expand the height.

Here is my ChatActivity XML:

<?xml version="1.0" encoding="utf-8"?>
<androidx.constraintlayout.widget.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    xmlns:tools="http://schemas.android.com/tools"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    tools:context=".chats.ChatActivity"
    android:background="?attr/bgColor"
>

    <LinearLayout
        android:id="@+id/llProgress"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_margin="8dp"
        android:orientation="vertical"
        app:layout_constraintEnd_toEndOf="parent"
        app:layout_constraintStart_toStartOf="parent"
        app:layout_constraintTop_toTopOf="parent" />


    <LinearLayout
        android:id="@+id/llSendChat"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_marginStart="8dp"
        android:layout_marginLeft="8dp"
        android:layout_marginEnd="8dp"
        android:layout_marginRight="8dp"
        android:layout_marginBottom="8dp"
        android:gravity="center_vertical"
        android:orientation="horizontal"
        app:layout_constraintBottom_toBottomOf="parent"
        app:layout_constraintEnd_toEndOf="parent"
        app:layout_constraintStart_toStartOf="parent">

        <LinearLayout
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:layout_marginRight="12dp"
            android:layout_weight="1"
            android:background="@drawable/gray_circle"
            android:orientation="horizontal"
            android:padding="3dp">

            <EditText
                android:id="@+id/etMessage"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:layout_gravity="center"
                android:layout_weight="1"
                android:background="@drawable/gray_circle"
                android:ems="10"
                android:hint="@string/enter_message"
                android:imeOptions="actionNone"
                android:inputType="textMultiLine"
                android:padding="8dp"
                android:textColor="?attr/messageEditTextColor"
                android:textColorHint="?attr/hintTextColor"
                android:textSize="14sp" />

            <ImageView
                android:id="@+id/ivAttachment"
                android:layout_width="wrap_content"
                android:layout_height="match_parent"
                android:background="?attr/selectableItemBackground"
                android:paddingLeft="8dp"
                android:paddingRight="8dp"
                android:tint="?attr/messageEditAttachmentTint"
                app:srcCompat="@drawable/ic_attachment" />
        </LinearLayout>

        <ImageView
            android:id="@+id/ivSend"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:background="@drawable/red_circle"
            android:foreground="?android:attr/selectableItemBackground"
            android:padding="8dp"
            android:tint="?attr/sendButtonIconColor"
            app:srcCompat="@drawable/ic_send"
            android:layout_gravity="right|bottom"/>
    </LinearLayout>

    <androidx.swiperefreshlayout.widget.SwipeRefreshLayout
        android:id="@+id/srlMessages"
        android:layout_width="0dp"
        android:layout_height="0dp"
        android:layout_marginStart="8dp"
        android:layout_marginLeft="8dp"
        android:layout_marginTop="8dp"
        android:layout_marginEnd="8dp"
        android:layout_marginRight="8dp"
        android:layout_marginBottom="8dp"
        app:layout_constraintBottom_toTopOf="@+id/llSendChat"
        app:layout_constraintEnd_toEndOf="parent"
        app:layout_constraintStart_toStartOf="parent"
        app:layout_constraintTop_toBottomOf="@+id/llProgress">

        <androidx.recyclerview.widget.RecyclerView
            android:id="@+id/rvMessages"
            android:layout_width="match_parent"
            android:layout_height="match_parent"
        />
    </androidx.swiperefreshlayout.widget.SwipeRefreshLayout>

</androidx.constraintlayout.widget.ConstraintLayout>

Upvotes: 0

Views: 43

Answers (1)

Prajwal Waingankar
Prajwal Waingankar

Reputation: 2710

Set max lines in EditText:

android:maxLines="5" 

or any number instead of 5.

Upvotes: 1

Related Questions