TextInputLayout & TextInputEditText hint

2019-09-12 06:25发布

问题:

This is my xml code to make a input text for user phone number but when it unfocused the hint label showed with larger text size my question is how to make the hint label activated like password even when there is no text in the field.

<android.support.design.widget.TextInputLayout
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:textColorHint="@color/colorText">

            <android.support.design.widget.TextInputEditText
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:hint="@string/phone_number"
                android:inputType="number"
                android:maxLines="1"
                android:textColorHint="@color/colorText" />

        </android.support.design.widget.TextInputLayout>

回答1:

Your hint is in the wrong place

<android.support.design.widget.TextInputLayout
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:hint="@string/phone_number"
            android:textColorHint="@color/colorText">

            <android.support.design.widget.TextInputEditText
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:inputType="number"
                android:maxLines="1"
                android:textColorHint="@color/colorText" />

        </android.support.design.widget.TextInputLayout>



回答2:

You can do it by setting a size in the string recource.

For example:

<string name="edittext_hint"><font size="15">Hint here!</font></string>

then in your XML just write

android:hint="@string/edittext_hint"

This will resault in a smaller text for the hint but the original size for the input text