How to make Android EditText expand vertically when full(如何使Android EditText在满时垂直扩展)
问题描述
我有这个 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在满时垂直扩展的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!
本文标题为:如何使Android EditText在满时垂直扩展


- 想使用ViewPager,无法识别android.support.*? 2022-01-01
- 如何检查发送到 Android 应用程序的 Firebase 消息的传递状态? 2022-01-01
- 在测试浓缩咖啡时,Android设备不会在屏幕上启动活动 2022-01-01
- Android - 拆分 Drawable 2022-01-01
- 用 Swift 实现 UITextFieldDelegate 2022-01-01
- 使用自定义动画时在 iOS9 上忽略 edgesForExtendedLayout 2022-01-01
- Android viewpager检测滑动超出范围 2022-01-01
- Android - 我如何找出用户有多少未读电子邮件? 2022-01-01
- MalformedJsonException:在第1行第1列路径中使用JsonReader.setLenient(True)接受格式错误的JSON 2022-01-01
- android 4中的android RadioButton问题 2022-01-01