本文介紹了如何使Android EditText在滿時垂直擴展的處理方法,對大家解決問題具有一定的參考價值,需要的朋友們下面隨著小編來一起學習吧!
問題描述
限時送ChatGPT賬號..
我有這個 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"/>
當框被用戶輸入的文本填滿時,它會向右滾動以為更多文本騰出空間,我不喜歡這種行為,如果 EditText 框在需要更多空間時向上擴展,我更喜歡它?有沒有辦法做到這一點?謝謝.
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
接受多行輸入. - 隨著更多文本行的添加,其高度會增加.
因此,要實現這一點,您需要設置:
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"/>
這篇關于如何使Android EditText在滿時垂直擴展的文章就介紹到這了,希望我們推薦的答案對大家有所幫助,也希望大家多多支持html5模板網!
【網站聲明】本站部分內容來源于互聯網,旨在幫助大家更快的解決問題,如果有圖片或者內容侵犯了您的權益,請聯系我們刪除處理,感謝您的支持!