TextInputLayout & TextInputEditText hint

耗尽温柔 提交于 2019-12-12 03:53:12

问题


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



来源:https://stackoverflow.com/questions/40958346/textinputlayout-textinputedittext-hint

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!