Change only lebel EditText to uppercase when using TextInputLayout

133 Views Asked by At

I am using the new TextInputLayout from material design library.

I only need to uppercase the Lebel(when positioned up), not the hint.

This is how should looks like

Here is my XML for my TextInputLayout and EditText

<com.google.android.material.textfield.TextInputLayout
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_marginBottom="@dimen/gap5"
        android:hint="@string/user"
      >

        <com.google.android.material.textfield.TextInputEditText
            android:id="@+id/input_user_login"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:inputType="textWebEmailAddress"
            android:autofillHints="emailAddress"/>

    </com.google.android.material.textfield.TextInputLayout>
1

There are 1 best solutions below

0
On

I don't think you can do this through the XML, I think you can kind of do it programmatically though.

Try something like this:

inputEditText.setOnFocusChangeListener(new View.OnFocusChangeListener() {
    @Override
    public void onFocusChange(View v, boolean hasFocus) {
        if (hasFocus) {
            inputLayout.setHint(getResources().getString(R.string.your_string_name).toUpperCase());
        } else {
            inputLayout.setHint(getResources().getString(R.string.your_string_name));
        }
    }
});