【问题标题】:Don't allow linebreaks in EditTexts不允许在 EditText 中换行
【发布时间】:2014-09-08 11:32:29
【问题描述】:

我想在 Android 上的 EditText 中限制字母的最大数量并禁止换行。

我知道我可以通过使用来限制字符

android:maxLength="..."

但是有没有办法禁止换行符?如果我使用

singleLine="true"

我的中是否还有换行符

editText.getText().toString()

?

【问题讨论】:

  • 你不能自己检查一下吗??
  • 这比仅仅问问题要花更长的时间,也许其他人也想知道。 :)

标签: android android-edittext line-breaks


【解决方案1】:

不,如果你使用不会有换行符

  singleLine="true"

因此,如果不想换行,则使用此选项是合适的

【讨论】:

    【解决方案2】:

    在你的edittext标签中添加android:maxLines="1"

    <EditText 
     .....
    android:maxLines="1" // add here
    </EditText>
    

    android:singleLine="true" 也应该可以工作。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2011-05-13
      • 1970-01-01
      • 2022-01-22
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2022-01-08
      相关资源
      最近更新 更多