1. Download our Official Android App: Forums for Android!

NumberPicker child text color

Discussion in 'Android Development' started by 4plus2, Sep 23, 2017.

  1. 4plus2

    4plus2 Lurker
    Thread Starter
    Rank:
    None
    Points:
    15
    Posts:
    3
    Joined:
    Sep 23, 2017

    Sep 23, 2017
    3
    0
    15
    Male
    Hello,

    I have been trying to set the color of the current item in a number picker.
    I thought the following would work in the onValueChange or onScrollStateChange

    ((EditText)numberPicker.getChildAt(numberPicker.getValue())).setTextColor(Color.RED);

    But it just crashes the emulator.
    Does anybody know how to set the colour of just the current child within a number picker?

    Thanks in advance

     

    Advertisement

  2. LV426

    LV426 I say we take off and nuke this place from orbit
    Moderator
    Rank:
     #10
    Points:
    1,988
    Posts:
    8,530
    Joined:
    Oct 16, 2015

    Oct 16, 2015
    8,530
    12,699
    1,988
    Male
    Software developer
    South West of England
  3. 4plus2

    4plus2 Lurker
    Thread Starter
    Rank:
    None
    Points:
    15
    Posts:
    3
    Joined:
    Sep 23, 2017

    Sep 23, 2017
    3
    0
    15
    Male
    Hello and thanks for your reply.

    What I am hoping to achieve is change the color of the current text showing in a number picker.
    The following line of code placed in the onCreate has this desired affect but the color is lost when scrolled.

    ((EditText)picker.getChildAt(0)).setTextColor(Color.RED);

    But when I place this code into the onValueChange it has no effect event if I do picker.invalidate()
    Sorry forgot about the trace. I was using getChildAt(newVal) and was getting null object reference but doesnt when I use getChildAt(0) which is what I want anyway.

    But still
    ((EditText)picker.getChildAt(0)).setTextColor(Color.RED);
    in either the OnValueChangeListener/onValueChange or OnScrollListener/OnScrollListener has no affect but in the onCreate method it does change the current picker value to red. The values above and below though I want to remain black.
    Thanks
     
  4. 4plus2

    4plus2 Lurker
    Thread Starter
    Rank:
    None
    Points:
    15
    Posts:
    3
    Joined:
    Sep 23, 2017

    Sep 23, 2017
    3
    0
    15
    Male
    Think I might just set the color of the divider rather than the text as the number picker is changed. Got this working.
     

Share This Page

Loading...