Numberpicker Textcolour
I have a ListView containing a TextView and a NumberPicker for each row. Whenever I start up the activity, the numbers of the NumberPicker are white (the same color as the backgrou
Solution 1:
I know the question is old. I founded the answer here: Change the text color of NumberPicker
Copy:
This code should solve your problem. The problem you are experiencing is because during the construction of NumberPicker it captures the EditText textColor and assigns to to a paint so it can draw the numbers above and below the edit text with the same color.
import java.lang.reflect.Field;
publicstaticbooleansetNumberPickerTextColor(NumberPicker numberPicker, int color)
{
finalintcount= numberPicker.getChildCount();
for(inti=0; i < count; i++){
Viewchild= numberPicker.getChildAt(i);
if(child instanceof EditText){
try{
FieldselectorWheelPaintField= numberPicker.getClass()
.getDeclaredField("mSelectorWheelPaint");
selectorWheelPaintField.setAccessible(true);
((Paint)selectorWheelPaintField.get(numberPicker)).setColor(color);
((EditText)child).setTextColor(color);
numberPicker.invalidate();
returntrue;
}
catch(NoSuchFieldException e){
Log.w("setNumberPickerTextColor", e);
}
catch(IllegalAccessException e){
Log.w("setNumberPickerTextColor", e);
}
catch(IllegalArgumentException e){
Log.w("setNumberPickerTextColor", e);
}
}
}
returnfalse;
}
Solution 2:
Are you using a Formatter? I had to use setDisplayedValues to fix the problem. I assume you have already solved this problem, but I'm posting this anyway, I for one was desperate looking for an answer, solved it by accident.
NumberPickernumberPicker=newNumberPicker(getActivity());
numberPicker.setMinValue(0);
numberPicker.setMaxValue(5);
String[] periodicityValues = {"Semanal", "Mensal", "Bimestral", "Trimestral", "Semestral", "Anual"};
numberPicker.setDisplayedValues(periodicityValues);
Post a Comment for "Numberpicker Textcolour"