【问题标题】:Android EditText.setError not working in not focusableAndroid EditText.setError 在不可聚焦的情况下不起作用
【发布时间】:2014-12-22 03:49:57
【问题描述】:

如何在不可聚焦的 EditText 中显示带有 setError 的文本错误?重要的是用户不要修改此 EditText,它将针对应用程序进行修改。也许我有不同于 focusable=false 的其他选项?

现在,我有它了:

<EditText
    android:id="@+id/date"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:clickable="true"
    android:ems="10"
    android:focusable="false"
    android:inputType="text"
    android:onClick="onClick" />

非常感谢!

【问题讨论】:

  • 或者不使用EditText?为什么不是 TextView?
  • 或者设置android:editable="false"?
  • 使用 EditText(并删除 focusable=false)我没有收到 setError 消息。
  • 不幸的是 editable=false 不起作用。有了它,我可以显示我的错误消息,但实际上我可以编辑这个字段。我也试过 inputType=none (相同但不弃用),结果是一样的。
  • 抱歉,在我 12 月 16 日 17:31 的评论中,我的意思是 TextView 而不是 EditText。

标签: android xml android-edittext focusable


【解决方案1】:

最后我认为这是不可能的......因为首先需要阻止文本,使用 focusable=false 或 TextView 进行,它还阻止了功能 setError。

带有 focusable = false 的 editText 我可以获得正确的可绘制对象(默认的红色感叹号)但没有文本。出于这个原因,我最后添加了带有 Toast 的文本。

这不完全是我想要的,但它是最相似的。

感谢您的帮助!

【讨论】:

    【解决方案2】:

    只需使用 TextView,如果您在某处出现错误,则使用 drawableRight 显示图像。 这是以编程方式执行的示例:https://stackoverflow.com/a/7380789/3864698

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2014-05-05
      • 2020-03-23
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2013-12-09
      相关资源
      最近更新 更多