Reputation: 273
I'm new to Android and I'm implementing NumberPicker to one of my activities in my app. Below is the excerpt of my code:
picker = (NumberPicker)findViewById(R.id.order_confirm_bring_time_minute_picker);
picker.setMinValue(15);
picker.setMaxValue(120);
picker.setWrapSelectorWheel(false);
setNumberPickerTextColor(picker, android.R.color.black);
public boolean setNumberPickerTextColor(NumberPicker numberPicker, int color)
{
final int count = numberPicker.getChildCount();
for(int i = 0; i < count; i++){
View child = numberPicker.getChildAt(i);
if(child instanceof EditText){
try{
Field selectorWheelPaintField = numberPicker.getClass()
.getDeclaredField("mSelectorWheelPaint");
selectorWheelPaintField.setAccessible(true);
((Paint)selectorWheelPaintField.get(numberPicker)).setColor(color);
((EditText)child).setTextColor(color);
numberPicker.invalidate();
return true;
}
catch(NoSuchFieldException e){
Log.d("setNumberPickerTextColor", "NoSuchFieldException");
}
catch(IllegalAccessException e){
Log.d("setNumberPickerTextColor", "IllegalAccessException");
}
catch(IllegalArgumentException e){
Log.d("setNumberPickerTextColor", "IllegalArgumentException");
}
}
}
return false;
}
I've looked into this post for the setNumberPickerTextColor
method. But it does not seem to work as I set my color to be changed to black, but it is not visible anymore. If I do not use the setNumberPickerTextColor
method, then my default color is white, which can be seen when I highlight the text in the EditText field of the NumberPicker.
This is a screenshot of the NumberPicker when the color is not changed.
This is a screenshot of the NumberPicker when the color is changed to black or any other color (I have tested and they give the same result).
Would there be a way to customize the text color in my NumberPicker? Also, I know it is a different question, but the colors of the top and bottom 'bar' as well because they do not fit the color theme of my app. Thanks in advance for help.
Upvotes: 0
Views: 3395
Reputation: 46
You need to pass the resolved color to the setTextColor method, not the resource id.
((EditText)child).setTextColor(getResources().getColor(color));
Upvotes: 1