Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

setHintTextColor() in EditText

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).

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.

like image 302
kartik trivedi Avatar asked Jun 22 '11 10:06

kartik trivedi


4 Answers

Simply add this in your layout for the EditText :

android:textColorHint="#FFFFFF"

like image 50
Anand Chavan Avatar answered Nov 06 '22 01:11

Anand Chavan


Use this to change the hint color. -

editText.setHintTextColor(getResources().getColor(R.color.white));

Solution for your problem -

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));
    }
});
like image 36
Sunil Kumar Sahoo Avatar answered Nov 06 '22 01:11

Sunil Kumar Sahoo


Default Colors:

android:textColorHint="@android:color/holo_blue_dark"

For Color code:

android:textColorHint="#33b5e5"
like image 23
kiran kumar Avatar answered Nov 06 '22 01:11

kiran kumar


Inside Layout Xml File We can Change Color of Hint.....

android:textColorHint="@android:color/*****"

you can replace * with color or color code.

like image 15
Akhil s Avatar answered Nov 06 '22 00:11

Akhil s