android EditText maxLength允许用户键入更多 [英] android EditText maxLength allows user to type more

查看:163
本文介绍了android EditText maxLength允许用户键入更多的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我已经在xml布局文件中为EditText小部件设置了maxLength属性,它确实限制了字符的显示.

I've already set the maxLength attribute for an EditText widget in the xml layout file, and it does limit the display of characters.

但是它仍然允许用户在键盘上按更多字母,并且退格删除这些多余的按键,而不是显示屏上的最后一个字母.

But it still allows the user to press more letters on the keyboard, and backspacing deletes these extra presses rather than the last letter on the display.

我相信这不是应该的样子.达到限制后,即使没有显示输入键,也应停止接受更多输入.

I believe this is not how it's supposed to be. Pressing keys after the limit has been reached should stop accepting more input even if it is not displayed.

对此有任何解决办法吗?

Any fix on this?

更新

根据以下答案,对于多行EditText,也添加textMultiLine属性.

Based on the answer below, for multiline EditText, add the textMultiLine attribute too.

android:inputType="textFilter|textMultiLine"

推荐答案

  1. 禁用自动建议(android:inputType="textFilter"textNoSuggestions):
  2. 设置maxLength

  1. Disable auto-suggestions(android:inputType="textFilter" or textNoSuggestions):
  2. Set maxLength

<EditText
   android:id="@+id/editText"
   android:inputType="textFilter"
   android:maxLength="8"
   android:layout_width="match_parent"
   android:layout_height="wrap_content" />

我希望这会有所帮助

这篇关于android EditText maxLength允许用户键入更多的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆