Change the Text Color of Numberpicker

Change the text color of NumberPicker

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;

public static void setNumberPickerTextColor(NumberPicker numberPicker, int color)
{

try{
Field selectorWheelPaintField = numberPicker.getClass()
.getDeclaredField("mSelectorWheelPaint");
selectorWheelPaintField.setAccessible(true);
((Paint)selectorWheelPaintField.get(numberPicker)).setColor(color);
}
catch(NoSuchFieldException e){
Log.w("setNumberPickerTextColor", e);
}
catch(IllegalAccessException e){
Log.w("setNumberPickerTextColor", e);
}
catch(IllegalArgumentException e){
Log.w("setNumberPickerTextColor", e);
}

final int count = numberPicker.getChildCount();
for(int i = 0; i < count; i++){
View child = numberPicker.getChildAt(i);
if(child instanceof EditText)
((EditText)child).setTextColor(color);
}
numberPicker.invalidate();
}

android Number picker text colour

As per our discussion in comments, the code here, requires a parameter from the Color class. Pass a color using this class.

how to select text color of numberpicker in flutter

There are two TextStyle

  • textStyle : others than selected text(except middle one)
  • selectedTextStyle: selected/middle textStyle
NumberPicker(
textStyle: TextStyle(color: Colors.pink),
selectedTextStyle: TextStyle(color: Colors.amber),
value: _currentValue,
minValue: 0,
maxValue: 100,
onChanged: (value) => setState(() => _currentValue = value),
),

Sample Image



Related Topics



Leave a reply



Submit