How to change Number Picker center text color in Android











up vote
7
down vote

favorite
1












I have implemented a custom Date Picker wherein I need to have custom colors for the number picker (Date picker uses Number picker inside) inside it as follows:
Expected



With the help of this answer I could make it look like this:
Actual Result



But as you see the actual date is getting shown in the yellow color instead of white.
Moreover, I tried doing it at run time like this:



npMonth.setOnValueChangedListener(new OnValueChangeListener() {

@Override
public void onValueChange(NumberPicker picker, int oldVal, int newVal) {
EditText et = ((EditText) npMonth.getChildAt(0));
et.setTextColor(getResources().getColor(R.color.gold));
}
});


But still no luck.



How to change just the center text color to white and keep the top and bottom text yellow?










share|improve this question
























  • See stackoverflow.com/a/15032921/544198
    – PearsonArtPhoto
    Nov 12 '14 at 12:56










  • Well that's rather discouraging @PearsonArtPhoto. All is done except fzr the central text color and I'll have to switch to some third party libs. I think I should spend some more time fiddling with it.
    – Rajkiran
    Nov 12 '14 at 13:28












  • @Rajkiran:I am also having the same issue. Can you please update the answer if you get the solution for above
    – Krishna Prasad
    Jul 21 '15 at 13:17












  • @Rajkiran : Did you find the solution for your question ??
    – codeRider
    Sep 14 '15 at 14:54










  • @codeRider and Krishna no luck folks.. unfortunately I haven't find any solution.
    – Rajkiran
    Sep 14 '15 at 15:07















up vote
7
down vote

favorite
1












I have implemented a custom Date Picker wherein I need to have custom colors for the number picker (Date picker uses Number picker inside) inside it as follows:
Expected



With the help of this answer I could make it look like this:
Actual Result



But as you see the actual date is getting shown in the yellow color instead of white.
Moreover, I tried doing it at run time like this:



npMonth.setOnValueChangedListener(new OnValueChangeListener() {

@Override
public void onValueChange(NumberPicker picker, int oldVal, int newVal) {
EditText et = ((EditText) npMonth.getChildAt(0));
et.setTextColor(getResources().getColor(R.color.gold));
}
});


But still no luck.



How to change just the center text color to white and keep the top and bottom text yellow?










share|improve this question
























  • See stackoverflow.com/a/15032921/544198
    – PearsonArtPhoto
    Nov 12 '14 at 12:56










  • Well that's rather discouraging @PearsonArtPhoto. All is done except fzr the central text color and I'll have to switch to some third party libs. I think I should spend some more time fiddling with it.
    – Rajkiran
    Nov 12 '14 at 13:28












  • @Rajkiran:I am also having the same issue. Can you please update the answer if you get the solution for above
    – Krishna Prasad
    Jul 21 '15 at 13:17












  • @Rajkiran : Did you find the solution for your question ??
    – codeRider
    Sep 14 '15 at 14:54










  • @codeRider and Krishna no luck folks.. unfortunately I haven't find any solution.
    – Rajkiran
    Sep 14 '15 at 15:07













up vote
7
down vote

favorite
1









up vote
7
down vote

favorite
1






1





I have implemented a custom Date Picker wherein I need to have custom colors for the number picker (Date picker uses Number picker inside) inside it as follows:
Expected



With the help of this answer I could make it look like this:
Actual Result



But as you see the actual date is getting shown in the yellow color instead of white.
Moreover, I tried doing it at run time like this:



npMonth.setOnValueChangedListener(new OnValueChangeListener() {

@Override
public void onValueChange(NumberPicker picker, int oldVal, int newVal) {
EditText et = ((EditText) npMonth.getChildAt(0));
et.setTextColor(getResources().getColor(R.color.gold));
}
});


But still no luck.



How to change just the center text color to white and keep the top and bottom text yellow?










share|improve this question















I have implemented a custom Date Picker wherein I need to have custom colors for the number picker (Date picker uses Number picker inside) inside it as follows:
Expected



With the help of this answer I could make it look like this:
Actual Result



But as you see the actual date is getting shown in the yellow color instead of white.
Moreover, I tried doing it at run time like this:



npMonth.setOnValueChangedListener(new OnValueChangeListener() {

@Override
public void onValueChange(NumberPicker picker, int oldVal, int newVal) {
EditText et = ((EditText) npMonth.getChildAt(0));
et.setTextColor(getResources().getColor(R.color.gold));
}
});


But still no luck.



How to change just the center text color to white and keep the top and bottom text yellow?







android android-datepicker numberpicker






share|improve this question















share|improve this question













share|improve this question




share|improve this question








edited May 23 '17 at 12:32









Community

11




11










asked Nov 12 '14 at 12:49









Rajkiran

8,311175592




8,311175592












  • See stackoverflow.com/a/15032921/544198
    – PearsonArtPhoto
    Nov 12 '14 at 12:56










  • Well that's rather discouraging @PearsonArtPhoto. All is done except fzr the central text color and I'll have to switch to some third party libs. I think I should spend some more time fiddling with it.
    – Rajkiran
    Nov 12 '14 at 13:28












  • @Rajkiran:I am also having the same issue. Can you please update the answer if you get the solution for above
    – Krishna Prasad
    Jul 21 '15 at 13:17












  • @Rajkiran : Did you find the solution for your question ??
    – codeRider
    Sep 14 '15 at 14:54










  • @codeRider and Krishna no luck folks.. unfortunately I haven't find any solution.
    – Rajkiran
    Sep 14 '15 at 15:07


















  • See stackoverflow.com/a/15032921/544198
    – PearsonArtPhoto
    Nov 12 '14 at 12:56










  • Well that's rather discouraging @PearsonArtPhoto. All is done except fzr the central text color and I'll have to switch to some third party libs. I think I should spend some more time fiddling with it.
    – Rajkiran
    Nov 12 '14 at 13:28












  • @Rajkiran:I am also having the same issue. Can you please update the answer if you get the solution for above
    – Krishna Prasad
    Jul 21 '15 at 13:17












  • @Rajkiran : Did you find the solution for your question ??
    – codeRider
    Sep 14 '15 at 14:54










  • @codeRider and Krishna no luck folks.. unfortunately I haven't find any solution.
    – Rajkiran
    Sep 14 '15 at 15:07
















See stackoverflow.com/a/15032921/544198
– PearsonArtPhoto
Nov 12 '14 at 12:56




See stackoverflow.com/a/15032921/544198
– PearsonArtPhoto
Nov 12 '14 at 12:56












Well that's rather discouraging @PearsonArtPhoto. All is done except fzr the central text color and I'll have to switch to some third party libs. I think I should spend some more time fiddling with it.
– Rajkiran
Nov 12 '14 at 13:28






Well that's rather discouraging @PearsonArtPhoto. All is done except fzr the central text color and I'll have to switch to some third party libs. I think I should spend some more time fiddling with it.
– Rajkiran
Nov 12 '14 at 13:28














@Rajkiran:I am also having the same issue. Can you please update the answer if you get the solution for above
– Krishna Prasad
Jul 21 '15 at 13:17






@Rajkiran:I am also having the same issue. Can you please update the answer if you get the solution for above
– Krishna Prasad
Jul 21 '15 at 13:17














@Rajkiran : Did you find the solution for your question ??
– codeRider
Sep 14 '15 at 14:54




@Rajkiran : Did you find the solution for your question ??
– codeRider
Sep 14 '15 at 14:54












@codeRider and Krishna no luck folks.. unfortunately I haven't find any solution.
– Rajkiran
Sep 14 '15 at 15:07




@codeRider and Krishna no luck folks.. unfortunately I haven't find any solution.
– Rajkiran
Sep 14 '15 at 15:07












1 Answer
1






active

oldest

votes

















up vote
0
down vote













The easiest way to do this



setNumberPickerTextColor(mNumberPicker);

public void setNumberPickerTextColor(NumberPicker numberPicker){
int color=Color.parseColor("#333333");

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();
}
catch(NoSuchFieldException e){
Log.e("setNumberPickerColor1", ""+e);
}
catch(IllegalAccessException e){
Log.e("setNumberPickerColor2", ""+e);
}
catch(IllegalArgumentException e){
Log.e("setNumberPickerColor3", ""+e);
}
}
}
}





share|improve this answer























  • From Review: Welcome to Stack Overflow! Please don't answer just with source code. Try to provide a nice description about how your solution works. See: How do I write a good answer?. Thanks
    – sɐunıɔןɐqɐp
    Oct 9 at 6:56











Your Answer






StackExchange.ifUsing("editor", function () {
StackExchange.using("externalEditor", function () {
StackExchange.using("snippets", function () {
StackExchange.snippets.init();
});
});
}, "code-snippets");

StackExchange.ready(function() {
var channelOptions = {
tags: "".split(" "),
id: "1"
};
initTagRenderer("".split(" "), "".split(" "), channelOptions);

StackExchange.using("externalEditor", function() {
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled) {
StackExchange.using("snippets", function() {
createEditor();
});
}
else {
createEditor();
}
});

function createEditor() {
StackExchange.prepareEditor({
heartbeatType: 'answer',
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader: {
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
},
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
});


}
});














draft saved

draft discarded


















StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f26887425%2fhow-to-change-number-picker-center-text-color-in-android%23new-answer', 'question_page');
}
);

Post as a guest















Required, but never shown

























1 Answer
1






active

oldest

votes








1 Answer
1






active

oldest

votes









active

oldest

votes






active

oldest

votes








up vote
0
down vote













The easiest way to do this



setNumberPickerTextColor(mNumberPicker);

public void setNumberPickerTextColor(NumberPicker numberPicker){
int color=Color.parseColor("#333333");

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();
}
catch(NoSuchFieldException e){
Log.e("setNumberPickerColor1", ""+e);
}
catch(IllegalAccessException e){
Log.e("setNumberPickerColor2", ""+e);
}
catch(IllegalArgumentException e){
Log.e("setNumberPickerColor3", ""+e);
}
}
}
}





share|improve this answer























  • From Review: Welcome to Stack Overflow! Please don't answer just with source code. Try to provide a nice description about how your solution works. See: How do I write a good answer?. Thanks
    – sɐunıɔןɐqɐp
    Oct 9 at 6:56















up vote
0
down vote













The easiest way to do this



setNumberPickerTextColor(mNumberPicker);

public void setNumberPickerTextColor(NumberPicker numberPicker){
int color=Color.parseColor("#333333");

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();
}
catch(NoSuchFieldException e){
Log.e("setNumberPickerColor1", ""+e);
}
catch(IllegalAccessException e){
Log.e("setNumberPickerColor2", ""+e);
}
catch(IllegalArgumentException e){
Log.e("setNumberPickerColor3", ""+e);
}
}
}
}





share|improve this answer























  • From Review: Welcome to Stack Overflow! Please don't answer just with source code. Try to provide a nice description about how your solution works. See: How do I write a good answer?. Thanks
    – sɐunıɔןɐqɐp
    Oct 9 at 6:56













up vote
0
down vote










up vote
0
down vote









The easiest way to do this



setNumberPickerTextColor(mNumberPicker);

public void setNumberPickerTextColor(NumberPicker numberPicker){
int color=Color.parseColor("#333333");

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();
}
catch(NoSuchFieldException e){
Log.e("setNumberPickerColor1", ""+e);
}
catch(IllegalAccessException e){
Log.e("setNumberPickerColor2", ""+e);
}
catch(IllegalArgumentException e){
Log.e("setNumberPickerColor3", ""+e);
}
}
}
}





share|improve this answer














The easiest way to do this



setNumberPickerTextColor(mNumberPicker);

public void setNumberPickerTextColor(NumberPicker numberPicker){
int color=Color.parseColor("#333333");

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();
}
catch(NoSuchFieldException e){
Log.e("setNumberPickerColor1", ""+e);
}
catch(IllegalAccessException e){
Log.e("setNumberPickerColor2", ""+e);
}
catch(IllegalArgumentException e){
Log.e("setNumberPickerColor3", ""+e);
}
}
}
}






share|improve this answer














share|improve this answer



share|improve this answer








edited Nov 12 at 6:45

























answered Oct 9 at 6:39









Mahendra Gohil

589




589












  • From Review: Welcome to Stack Overflow! Please don't answer just with source code. Try to provide a nice description about how your solution works. See: How do I write a good answer?. Thanks
    – sɐunıɔןɐqɐp
    Oct 9 at 6:56


















  • From Review: Welcome to Stack Overflow! Please don't answer just with source code. Try to provide a nice description about how your solution works. See: How do I write a good answer?. Thanks
    – sɐunıɔןɐqɐp
    Oct 9 at 6:56
















From Review: Welcome to Stack Overflow! Please don't answer just with source code. Try to provide a nice description about how your solution works. See: How do I write a good answer?. Thanks
– sɐunıɔןɐqɐp
Oct 9 at 6:56




From Review: Welcome to Stack Overflow! Please don't answer just with source code. Try to provide a nice description about how your solution works. See: How do I write a good answer?. Thanks
– sɐunıɔןɐqɐp
Oct 9 at 6:56


















draft saved

draft discarded




















































Thanks for contributing an answer to Stack Overflow!


  • Please be sure to answer the question. Provide details and share your research!

But avoid



  • Asking for help, clarification, or responding to other answers.

  • Making statements based on opinion; back them up with references or personal experience.


To learn more, see our tips on writing great answers.





Some of your past answers have not been well-received, and you're in danger of being blocked from answering.


Please pay close attention to the following guidance:


  • Please be sure to answer the question. Provide details and share your research!

But avoid



  • Asking for help, clarification, or responding to other answers.

  • Making statements based on opinion; back them up with references or personal experience.


To learn more, see our tips on writing great answers.




draft saved


draft discarded














StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f26887425%2fhow-to-change-number-picker-center-text-color-in-android%23new-answer', 'question_page');
}
);

Post as a guest















Required, but never shown





















































Required, but never shown














Required, but never shown












Required, but never shown







Required, but never shown

































Required, but never shown














Required, but never shown












Required, but never shown







Required, but never shown







Popular posts from this blog

Bressuire

Vorschmack

Quarantine