問(wèn)題描述
我有一個(gè)視圖,其中有兩個(gè)文本框,用戶可以從同一屏幕上的另一個(gè)視圖中選擇文本顏色(通過(guò)對(duì)話框).
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).
因此,當(dāng)用戶通過(guò)對(duì)話框更改顏色時(shí),我正在更改 EditText
文本及其提示的顏色.但是,當(dāng)用戶選擇其他顏色后 EditText
中有一些文本可用時(shí),該文本將以該顏色出現(xiàn).但是,如果我刪除所有這些文本,那么 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.
例如,當(dāng)前如果我在文本框中有紅色并且用戶選擇綠色,那么文本是綠色的.但是,如果我刪除該文本,那么即使我在代碼中更改提示顏色,提示文本也會(huì)變?yōu)榧t色.僅當(dāng)那里有一些文本時(shí)才會(huì)出現(xiàn)此問(wèn)題.如果它是空白的并且有提示文本,那么問(wèn)題就不會(huì)出現(xiàn).
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.
推薦答案
使用它來(lái)改變提示顏色.-
Use this to change the hint color. -
editText.setHintTextColor(getResources().getColor(R.color.white));
解決您的問(wèn)題 -
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));
}
});
這篇關(guān)于EditText 中的 setHintTextColor()的文章就介紹到這了,希望我們推薦的答案對(duì)大家有所幫助,也希望大家多多支持html5模板網(wǎng)!