【问题标题】:Multiline edittext with text limit带有文本限制的多行编辑文本
【发布时间】:2020-02-28 11:40:12
【问题描述】:

如何创建带有文本限制的多行编辑文本? 我设置了edittext的maxLength,但它使edittext成为单行,如果我将inputType添加到textMultiLine,那么设置为actionDone的imeOptions将不会显示。我不想为 maxLines 属性设置静态值。

<EditText
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:hint="@string/activityNameHint"
        android:inputType="textMultiLine"
        android:maxLength="500"
        android:imeOptions="actionDone"
       />

而且当编辑文本达到其限制时,键盘仍然允许文本,这使得删除文本变得困难。如何解决这个问题?

【问题讨论】:

  • 无法复制问题

标签: android android-edittext


【解决方案1】:
new TextWatcher() {
@Override
public void beforeTextChanged(CharSequence charSequence, int i, int i1, int i2) {

}

@Override
public void onTextChanged(CharSequence charSequence, int i, int i1, int i2) {

}

@Override
public void afterTextChanged(Editable editable) {

}

});

通过覆盖文本更改侦听器,您可以在 ontextchange() 中指定最大长度并在那里添加条件并做任何您想做的事情

【讨论】:

    【解决方案2】:

    你可以试试这个代码:

    android:maxLines="3"
    android:minLines="3"
    android:gravity="left"
    android:maxLength="500"
    android:inputType="textMultiLine"
    

    【讨论】:

      猜你喜欢
      • 2019-10-18
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2023-04-03
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多