是否可以根据文本是 float 在 EditText
中还是在 EditText
中来更改 float 提示的文本?
例如,当字段为空时,我希望看到文本“你的名字”,而当提示 float 时,我希望看到文本“姓名”。
现在是这样的:
<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>
最佳答案
这将在 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>
关于android - 可以更改 float EditText 提示的文本吗?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/31789265/