I need to show a success state on Material's TextInputLayout. I just need the same UI as this layout shows when an error is set. Following is what I need:
class CustomTextInputLayout(
context: Context,
attributes: AttributeSet?,
): TextInputLayout(context, attributes) {
fun setSuccessMode(successText: CharSequence?)
fun setErrorMode(errorText: CharSequence?)
fun setHelperTextMode(helperText: CharSequence?)
}
I am not sure how to do this using themes and styles. I planned to trick TextInputLayout to show different colours on the basis of a variable, but still use setError() functionality. But, I don't think I can change theme for TextInputLayout in runtime easily. Also, introducing a variable will require me to preserve this over savedState changes.
This is what I ended up using:
I am unsure if this is the best way. And, I still kinda feel like I should do this using theming/styling/selectors, but I don't know if something like that is possible.
I didn't want to extend the
TextInputLayoutin the end because this implementation can work without a custom class. This, also, saves me from managing the state of the view.This is how it looks as of now (Material3):
error
success
idle/helper-text