Android Guy
Android Guy

Reputation: 583

Comments section like instagram for edit text

I am trying to make the comments section the same as Instagram for edit text. My requirement is to show send as imeOptions with multiline typing and expanding the edit text.

This is what I tried, it starts typing in the next line but the edit text not expanding.

<androidx.appcompat.widget.AppCompatEditText
            android:id="@+id/etComment"
            android:layout_width="0dp"
            android:layout_height="wrap_content"
            android:layout_weight="1"
            android:background="@android:color/transparent"
            android:hint="Add comment here..."
            android:imeOptions="actionSend"
            android:inputType="textCapSentences"
            android:lineSpacingExtra="2dp"
            android:lineSpacingMultiplier="1.2"
            android:maxHeight="@dimen/margin_100"
            android:maxLength="200"
            android:maxLines="10"
            android:singleLine="false"
            android:textColor="@color/white"
            android:textColorHint="@color/hint_color"
            android:textSize="14sp" />

Upvotes: 0

Views: 365

Answers (2)

Maroof
Maroof

Reputation: 891

Your XML is nearby correct. Please add inputType = 'text' as well.

<androidx.appcompat.widget.AppCompatEditText
            android:id="@+id/etComment"
            android:layout_width="0dp"
            android:layout_height="wrap_content"
            android:layout_weight="1"
            android:background="@android:color/transparent"
            android:hint="Add comment here..."
            android:inputType="text|textCapSentences"
            android:imeOptions="actionSend"
            android:lineSpacingExtra="2dp"
            android:lineSpacingMultiplier="1.2"
            android:maxHeight="@dimen/margin_100"
            android:maxLength="200"
            android:singleLine="false"
            android:textColor="@color/white"
            android:textColorHint="@color/hint_color"
            android:textSize="14sp" />

Also, in activity class

etComment.setHorizontallyScrolling(false);
etComment.setMaxLines(Integer.MAX_VALUE);

Let me know, if that works.

Upvotes: 1

Hani
Hani

Reputation: 149

you need to catch text change and change the height manually according the number of lines entered by user for expanding or sharing

Upvotes: 0

Related Questions