我有一个视图,其中有两个文本框,用户可以从同一屏幕上的另一个视图中选择文本颜色(通过对话框).
I have View in which there are two text boxes, and the user can select text color from another view on the same screen (through dialog box).
因此,当用户通过对话框更改颜色时,我正在更改 EditText
文本及其提示的颜色.但是,当用户选择其他颜色后 EditText
中有一些文本可用时,该文本将以该颜色出现.但是,如果我删除所有这些文本,那么 HintText 的颜色就是以前的颜色.
So when the user changes color via dialog box, I am changing color of EditText
text and its hint. But when there is some text is available in EditText
after that user selects other color, then that text is coming in that color. But if I remove all that text then the color of HintText is that of the previous color.
例如,当前如果我在文本框中有红色并且用户选择绿色,那么文本是绿色的.但是,如果我删除该文本,那么即使我在代码中更改提示颜色,提示文本也会变为红色.仅当那里有一些文本时才会出现此问题.如果它是空白的并且有提示文本,那么问题就不会出现.
For example, currently if I have red color in text box and the user selects green color so text is there in green color. But if I remove that text then hint text are coming in red even if I change hint color in code. This problem only comes when there is some text there. if it is blank and hint text is there then problem is not coming.
使用它来改变提示颜色.-
Use this to change the hint color. -
editText.setHintTextColor(getResources().getColor(R.color.white));
解决您的问题 -
editText.addTextChangedListener(new TextWatcher() {
@Override
public void onTextChanged(CharSequence arg0, int arg1, int arg2,int arg3){
//do something
}
@Override
public void beforeTextChanged(CharSequence arg0, int arg1, int arg2, int arg3) {
//do something
}
@Override
public void afterTextChanged(Editable arg0) {
if(arg0.toString().length() <= 0) //check if length is equal to zero
tv.setHintTextColor(getResources().getColor(R.color.white));
}
});
这篇关于EditText 中的 setHintTextColor()的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持html5模板网!