Search code examples
androidnumberpicker

Android Number Picker Text Colour Random Color


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);

Solution

  • 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