androidxmlandroid-edittextandroid-textinputlayout

Fixing hint placement in my Android application


So, I use TextInputLayout and EditText to input email, but I have some trouble with hint placement. I also don't know how to change the color of this "I" symbol. Here is my XML for this email field:

<com.google.android.material.textfield.TextInputLayout
        style="@style/ThemeOverlay.Material3.AutoCompleteTextView.OutlinedBox"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_gravity="center"
        android:textColorHint="@color/black"
        app:hintTextColor="@color/black"
        app:boxStrokeColor="@color/black">

        <EditText
            android:layout_width="350dp"
            android:layout_height="wrap_content"
            android:hint="@string/test_email"
            android:textSize="20sp"
            android:id="@+id/logEmail"
            android:layout_gravity="center"
            android:inputType="textEmailAddress"
            android:layout_marginTop="20dp"
            android:layout_marginStart="30dp"
            android:layout_marginEnd="30dp"
            android:textColorHint="#616161"/>

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

Solution

  • Couple of mistakes here:

    1. Wrong child view for com.google.android.material.textfield.TextInputLayout.
    2. Wrong style attribute value.
    3. android:hint="@string/test_email" is used at wrong place.

    Use code below:

    <com.google.android.material.textfield.TextInputLayout
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:layout_gravity="center"
            android:hint="app"
            app:cursorColor="@android:color/holo_red_dark"
            app:hintEnabled="true">
    
            <com.google.android.material.textfield.TextInputEditText
                android:id="@+id/logEmail"
                android:layout_width="350dp"
                android:layout_height="wrap_content"
                android:inputType="textEmailAddress" />
    
        </com.google.android.material.textfield.TextInputLayout>
    

    In the code above:

    1. Have corrected all the errors.
    2. Used app:cursorColor to define caret (the "|" thing) color.