Elye Elye -4 years ago 168
Android Question

InputTextLayout, setting Error Text as Helper Text (of different color)

Android provided a widget called TextInputLayout
https://developer.android.com/reference/android/support/design/widget/TextInputLayout.html

This could provide Hint and Error, which is excellent wrapper around EditText.

There's also seemingly a guideline on it in https://material.google.com/patterns/errors.html#errors-user-input-errors

With that, it show Hint and Error. And also it has Helper Text. This is where it is useful for password setup. E.g. before someone enter a password, the ErrorText is show as HelperText, distinguish by a different color (in grey instead of red as per the example).

When I look at TextInputLayout, it does have the two functions

setError(CharSequence error)


and

setHint(CharSequence hint)


However, there's no way to change the ErrorText to HelperText. Did I miss anything, or it's just TextInputLayout provided by Support Library is not giving us the feature as per Google recommended in its material guideline?

p/s: I know how to change ErrorText color by setting through the style. But this doesn't help as it can't change dynamically while the app is running (e.g. change the state from error to helper and vice versa).

Answer Source

Found this extend version of TextInputLayout. https://gist.github.com/drstranges/1a86965f582f610244d6

This manage to add the Helper Text naturally.

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download