• After 15+ years, we've made a big change: Android Forums is now Early Bird Club. Learn more here.

NumberPicker child text color

4plus2

Lurker
Sep 23, 2017
3
0
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
 
Please include the stack trace from the Logcat view.
See here for some useful information -

https://androidforums.com/threads/please-read-me-before-posting.987318/

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()
Please include the stack trace from the Logcat view.
See here for some useful information -

https://androidforums.com/threads/please-read-me-before-posting.987318/

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
 
Upvote 0

BEST TECH IN 2023

We've been tracking upcoming products and ranking the best tech since 2007. Thanks for trusting our opinion: we get rewarded through affiliate links that earn us a commission and we invite you to learn more about us.

Smartphones