Material Design specify an asterisk for the required fields that is part of the hint text, and of the same color (not in red like you showed in your question).
In Kotlin this is really simple:
1.Define this extension method:
fun TextInputLayout.markRequired() {
hint = "$hint *"
}
2.Use it:
input_first_name.markRequired()
If you still want the asterisk red, despite being discouraged by Material Design guidelines, you can use AndroidX Core KTX that way:
fun TextInputLayout.markRequiredInRed() {
hint = buildSpannedString {
append(hint)
color(Color.RED) { append(" *") } // Mind the space prefix.
}
}
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…