可以更改浮动 EditText 提示的文本吗?

Possible to change text of the floating EditText hint?

是否可以根据文本是浮动在 EditText 上还是在 EditText 内来更改浮动提示的文本?

例如,当字段为空时,我希望看到文本"Your name",而当提示为浮动时,我希望看到文本"Name"。

现在是这样的:

<android.support.design.widget.TextInputLayout
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                >

                <EditText
                    android:layout_width="match_parent"
                    android:layout_height="wrap_content"
                    android:hint="Your name"
                    android:textColorHint="@color/dark_grey"
                    android:textColor="@color/dark_grey"
                    android:background="@drawable/edittext_bg"
                    >
                    <requestFocus/>
                </EditText>

</android.support.design.widget.TextInputLayout>
EditText.addTextChangedListener(new TextWatcher() {
        @Override
        public void onTextChanged(CharSequence s, int start, int before, int count) {
            // TODO Auto-generated method stub              
        }

        @Override
        public void beforeTextChanged(CharSequence s, int start, int count,
                int after) {
            // TODO Auto-generated method stub      
        }
        @Override
        public void afterTextChanged(Editable s) {
            EditText.setHint("Name");    
        }
    });

这将在 TextInputLayout 和 EditText 的 onFocusChangeListener 的帮助下完成,

textInputLayoutEmail.setHint("Enter your Email id");

editText.setOnFocusChangeListener(new View.OnFocusChangeListener() {
            @Override
            public void onFocusChange(View v, boolean hasFocus) {
                textInputLayoutEmail.setHint("Email");
            }
        });

从 xml 文件中的 EditText 中删除提示,

<android.support.design.widget.TextInputLayout
    android:layout_width="match_parent"
    android:layout_height="wrap_content">

    <EditText
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:textColorHint="@color/dark_grey"
        android:textColor="@color/dark_grey"
        android:background="@drawable/edittext_bg">

        <requestFocus />
    </EditText>

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