I've looked at most all of the threads on this and none provided an answer that works. Styling the NumberPicker does not work (as per this thread: NumberPicker textColour)
Setting the style attribute on the numberPicker to a style that has a color item does not have any effect either. Nor does setting the textColor attribute on the numberPicker XML do anything.
Closest I've got to this is using the numberPicker to cast its getChildAt() to an EditText and then do setColor() on that EditText, but that only changes the color of the child once upon initialization and then every time it is selected from thereon; not what I am looking for either.
Any help? Thanks
For me setting
android:textColorPrimary
in my theme did nothing, looking at the source code for theNumberPicker
it decides the text color from theEditText
input thus one need to set theandroid:editTextColor
instead.The solution I tried and worked for me is:
In styles.xml add:
Then use it like this inside your layout:
Based on reflection reject on Android SDK >= 29 better to modify Simon's answer:
In SDK >= 29 NumberPicker have .setTextColor() method.
It's easy with my NumberPicker library.
The accepted answer is overly complicated. A much simpler approach that worked for me was to override the:
textColorPrimary
attribute of the theme I was using.It did the job quite well!
Instead of changing every text color to the color you want, better just changing all editText color. NumberPicker actually has a child EditText that display the numbers.
This worked for me. And although I have white text in the buttons, they havent changed.