3

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 background).

I tried applying a style as suggested here, here, and here ; to no avail.

Any other suggestions?

-

NumberPicker.xml

<NumberPicker 
    android:id="@+id/npMaterialAmount"
    android:layout_alignParentRight="true"
    android:layout_width="wrap_content"
    android:layout_height="75dp"
    style="@style/npColour"/>

-

Tried style 1:

<style name = "npColour" >
    <item name = "android:textColor">#000000</item>
</style>

-

Tried style 2:

<style name = "npColour" parent ="@android:style/Theme.Holo.Light">
</style>

-

... and the list goes on...

Community
  • 1
  • 1
ClaireG
  • 1,214
  • 2
  • 10
  • 22

2 Answers2

2

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;

public static 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.w("setNumberPickerTextColor", e);
            }
            catch(IllegalAccessException e){
                Log.w("setNumberPickerTextColor", e);
            }
            catch(IllegalArgumentException e){
                Log.w("setNumberPickerTextColor", e);
            }
        }
    }
    return false;
}
Community
  • 1
  • 1
phil
  • 1,139
  • 1
  • 11
  • 21
-3

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.

    NumberPicker numberPicker = new NumberPicker(getActivity());
    numberPicker.setMinValue(0);
    numberPicker.setMaxValue(5);     
    String[] periodicityValues = {"Semanal", "Mensal", "Bimestral", "Trimestral", "Semestral", "Anual"};
    numberPicker.setDisplayedValues(periodicityValues);
jszobody
  • 26,350
  • 5
  • 57
  • 67