首页 > 解决方案 > 用于编辑文本的评论部分(如 instagram)

问题描述

我正在尝试使评论部分与 Instagram 的编辑文本相同。我的要求是使用多行输入和扩展编辑文本将发送显示为 imeOptions。

这是我尝试过的,它开始在下一行输入,但编辑文本没有扩展。

<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" />

标签: androidandroid-edittextinstagram

解决方案


您的 XML 在附近是正确的。请同时添加 inputType = 'text'。

<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" />

另外,在活动课上

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

让我知道,如果这有效。


推荐阅读