是否可以在文本输入布局上设置错误而不显示任何错误消息(我已在其他地方执行此操作)?。
textinputlayout.setError("");
不幸的是,将无法运作。
我基本上需要的是textInputLayout将其线条颜色更改为红色,但我需要以编程方式执行此操作。谢谢
答案 0 :(得分:2)
您可以隐藏布局并显示错误。像这样:
[
{
"_id": "59982d3c7ca25936f8c327c8",
"name": "Mr. Kitty",
"roles": ["vip", "birthday cat"],
"dateOfLastParty": "2017-06-02"
},
{
"_id": "59982d3c7ca25936f8c327c9",
"name": "Snuffles",
"roles": ["best looking cat"],
"dateOfLastParty": "2017-06-01"
},
...
{
"_id": "59982d3c7ca25936f8c327c4",
"name": "Sad Face McLazytown",
"roles": [],
"dateOfLastParty": null
},
]
答案 1 :(得分:0)
希望它不会太晚,但setError
背后的代码是:
if (!mErrorEnabled) {
if (TextUtils.isEmpty(error)) {
// If error isn't enabled, and the error is empty, just return
return;
}
}
这意味着一个简单的解决方法是:
textinputlayout.setError(" ");
请注意,这会使TextView显示错误信息 - 因此即使它是空的,它也会使TextInputLayout更高
因为这传递了处理空错误消息请求的不太经过深思熟虑的情况。
答案 2 :(得分:0)
错误文本(甚至“”)将在 TextInputLayout 中占据/保留一些高度。如果你也想摆脱它,那么
<com.google.android.material.textfield.TextInputLayout
...
app:errorTextAppearance="@style/MyZeroSizeTextAppearance"
...
>
文字外观:
<style name="MyZeroSizeTextAppearance">
<item name="android:textSize">0sp</item>
</style>
然后
textinputlayout.setError(" ");