Android数字选择器文本颜色随机颜色



所以我浏览了很多,没有看到任何能帮助我的东西(是的,我在这里看到了答案),但它不适用于随机数(或者如果你能帮助我,那将是惊人的),如果有人能帮我,我愿意提供一个小的贝宝礼物,因为这会让我发疯。我将分享我目前正在尝试的内容和我的颜色列表

public void setNumberPickerTextColor(NumberPicker numberPicker, int color){
    EditText et = ((EditText) numberPicker.getChildAt(0));
    et.setTextColor(getResources().getColor(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);

所以我在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);

然后使用上面链接中的答案,这将在每次

时随机生成一个随机颜色

最新更新