1

So I have been browsing a lot and not seen anything that can help me, (yes I have seen the answer here) but it would not work with a random number(or if you could help me make it work would be amazing), if anyone could help me I am willing to offer a small paypal gift since this is driving me nuts. I will share what I'm trying currently and my list of colors

public void setNumberPickerTextColor(NumberPicker numberPicker, int color){
    EditText et = ((EditText) numberPicker.getChildAt(0));
    et.setTextColor(getResources().getColor(color));
}

this is my random color

private int [] textColours = new int[]{
    R.color.text_color_1, R.color.text_color_2, R.color.text_color_3,
    R.color.text_color_4, R.color.text_color_5, R.color.text_color_6,
    R.color.text_color_7, R.color.text_color_8, R.color.text_color_9,
    R.color.text_color_10
}; 
int randomColorPicker = (int)(Math.random() * textColours.length);
setNumberPickerTextColor(pickerOne, randomColorPicker);
Community
  • 1
  • 1
androidkid
  • 21
  • 4
  • 1
    Forget the "gift" stuff. Pay it forward by helping others :) That being said, did you manage to set a fixed text color for the EditText? – Bö macht Blau Nov 25 '15 at 14:59
  • ok, I think the link you give in your question can cover that. You have to keep in mind that the "int color" in the first answer [ is an int containing alpha as well as r,g,b](http://developer.android.com/reference/android/graphics/Paint.html#setColor%28int%29), not a R.color.whatever number – Bö macht Blau Nov 25 '15 at 15:07

1 Answers1

1

So I used the link in the description with help from 0X0nosugar

Random rnd = new Random();
int color = Color.argb(255, rnd.nextInt(256), rnd.nextInt(256), rnd.nextInt(256));

//set the picker text color from the method below and the random number above
setNumberPickerTextColor(pickerOne, color);
setNumberPickerTextColor(pickerTwo, color);
setNumberPickerTextColor(pickerThree, color);
setNumberPickerTextColor(pickerTolerance, color);

and then using the answer from the link above this will randomly generate a random color everytime

Gaëtan Maisse
  • 11,587
  • 9
  • 41
  • 45
androidkid
  • 21
  • 4