問題描述
我有這個 EditText
I have this EditText
<EditText
android:layout_width="match_parent"
android:layout_height="72dp"
android:hint="@string/write_message"
android:textColorHint="@color/primary_color"
android:ems="10"
android:imeOptions="actionDone"
android:inputType="textImeMultiLine"
android:id="@+id/message_input"
android:layout_gravity="center_horizontal"
android:backgroundTint="@color/primary_color"/>
當(dāng)框被用戶輸入的文本填滿時,它會向右滾動以為更多文本騰出空間,我不喜歡這種行為,如果 EditText 框在需要更多空間時向上擴(kuò)展,我更喜歡它?有沒有辦法做到這一點?謝謝.
When the box is filled up with user inputted text, it scrolls to the right to make room for more text, I do not like this behavior, and would prefer it if the EditText box expanded upwards when it needs more room? Is there a way to do this? Thanks.
推薦答案
是的,這實際上涉及到兩件事:
Yes, this actually involves two things:
- 使
EditText
接受多行輸入. - 隨著更多文本行的添加,其高度會增加.
因此,要實現(xiàn)這一點,您需要設(shè)置:
Therefore, to achieve this, you need to set up:
android:inputType="textMultiLine"
android:layout_height="wrap_content"
(請注意 textMultiLine
和 textImeMultiLine
).
(Be mindful of the difference between textMultiLine
and textImeMultiLine
).
完整的 XML 片段是:
The full XML snippet would be:
<EditText
android:layout_width="match_parent"
android:inputType="textMultiLine"
android:layout_height="wrap_content"
android:hint="@string/write_message"
android:textColorHint="@color/primary_color"
android:ems="10"
android:imeOptions="actionDone"
android:id="@+id/message_input"
android:layout_gravity="center_horizontal"
android:backgroundTint="@color/primary_color"/>
這篇關(guān)于如何使Android EditText在滿時垂直擴(kuò)展的文章就介紹到這了,希望我們推薦的答案對大家有所幫助,也希望大家多多支持html5模板網(wǎng)!