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 mDefaultTextColor
to 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
Rotating Image. Animation List or Animated Rotate? (Android)
How to List All Files and Folders Locating on Sd Card
Crop Square Image to Circle - Programmatically
Items Inside Gridview Getting Repeated When Screen Scrolls
Google Map for Android My Location Custom Button
How to Find Memory Leaks from Native Code in Android
Android View Layout_Width - How to Change Programmatically
How to Forward My Localhost Ip-Address to an Android Emulator
Android Listview with Checkbox Problem
Fragmentmanager Is Already Executing Transactions. When Is It Safe to Initialise Pager After Commit
Camera Preview Is in Portrait Mode But Image Captured Is Rotated
How to Generate The Aac Adts Elementary Stream with Android Mediacodec
Bitmapfactory.Decodestream Out of Memory Despite Using Reduced Sample Size
How to Import an Existing Project from Github into Android Studio
Ionic Cordova App Stopped Compiling After Google's June 17Th Firebase Sdk Update