Sethinttextcolor() in Edittext

setHintTextColor() in EditText

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));
}
});

Change EditText hint color when using TextInputLayout

Looks like the parent view had a style for a 3rd party library that was causing the EditText to be white.

android:theme="@style/com_mixpanel_android_SurveyActivityTheme"

Once I removed this everything worked fine.

Programmatically set TextInputLayout Hint Text Color and Floating Label Color

I changed focused color with reflection. Here's the snippet it may help someone.

private void setUpperHintColor(int color) {
try {
Field field = textInputLayout.getClass().getDeclaredField("mFocusedTextColor");
field.setAccessible(true);
int[][] states = new int[][]{
new int[]{}
};
int[] colors = new int[]{
color
};
ColorStateList myList = new ColorStateList(states, colors);
field.set(textInputLayout, myList);

Method method = textInputLayout.getClass().getDeclaredMethod("updateLabelState", boolean.class);
method.setAccessible(true);
method.invoke(textInputLayout, true);

} catch (Exception e) {
e.printStackTrace();
}
}

EDIT 2018-08-01:

If you are using design library v28.0.0 and later, fields had changed from mDefaultTextColorto defaultHintTextColor and from mFocusedTextColor to focusedTextColor.

Check decompiled class for other fields.

how to change EditText hint color in android

I think you should set error instead

editText.setError(getString(R.string.error_required));

but if you want that

editText.setHint()
editText.setHintTextColor

Change HintTextColor and Cursor Color of TextInputEditText Programmatically

For those who work with TextInputLayout, I found the answer. Just simply use:

textInputLayout.setHintTextColor(ColorStateList.valueOf(your_color));
textInputLayout.setBoxStrokeColor(your_color);

And for the cursor:

editText.setTextCursorDrawable();


Related Topics



Leave a reply



Submit