I am using the new TextInputLayout from the design library. I am able to get it to show and to change the color of the floating label. Unfortunately it does not change the text to uppercase.
I don't want to change my strings.xml, because I just want this label to be uppercase. I have tried changing the textAllCaps in layout, styles and programmatically but the case of EditText hint always shows exactly as the strings.xml.
Here is my XML for my TextInputLayout and EditText
<android.support.design.widget.TextInputLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android.support.design:hintTextAppearance="@style/TextInputLayout">
<EditText
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:id="@+id/city"
android:textColorHint="@color/black"
android:hint="@string/city" />
</android.support.design.widget.TextInputLayout>
And here is the style I am using for the TextInputLayout (I tried using the only "textAllCaps" (without "android:") attribute but didn't do anything for me):
<style name="TextInputLayout" parent="@android:style/TextAppearance">
<item name="android:textAllCaps">true</item>
</style>
The solution is almost the same with @Janvi, but it's solved by BindingAdapter which can be used in xml instead of codes:
@BindingAdapter("android:hint")
fun setTextInputLayoutHint(textInputLayout: TextInputLayout, hint: CharSequence?) {
textInputLayout.hint = hint?.toString()?.toUpperCase()
}
<com.google.android.material.textfield.TextInputLayout
android:id="@+id/til_first_name"
android:hint="@{@string/first_name}"
PS:
The hint should be set on TextInputLayout, rather than the TextInputEditText or EditText. https://material.io/develop/android/components/text-input-layout/
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With