1
public static void setNumberPickerTextColor(Context context,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);
                    numberPicker.invalidate();
                    ((EditText)child).setTextColor(color);

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

            } 
        } 
    }

The above code changing color of all options . But I want to change only selected option color

Thanks in Advance!!!!

Anoop M Maddasseri
  • 10,213
  • 3
  • 52
  • 73

1 Answers1

0

You're using a for loop on all options to change the color of all options.

You want to change only the color of the selected item, so instead of the for loop, you can take only the selected child:

View child = numberPicker.getChildAt(numberPicker.getValue());
//change the color of this child to the new color
  • Please view this http://stackoverflow.com/questions/26887425/how-to-change-number-picker-center-text-color-in-android This is my exact requirement . – Khadaraiah Koneti Jul 21 '15 at 13:17
  • i'm not sure if numberPickers behave like spinners where the selected child is the child at 0. You can try the code of the link you gave with getChildAt(newVal) instead of getChildAt(0) (the newVal and oldVal parameters of the OnValueChange function give the position of the selected item and the position of the item that was selected right before) – Henri Schritz Jul 21 '15 at 16:44