0

I am currently working on an android APP and I have a list of predefined color in my colors.xml.

Now what I want to achieve is that I want to give the user the opportunity of selecting a color and from the color the user select, I want to display various color (randomly) in the background that matches the global color the user selects, such that those colors will be changing at interval. These colors that will be displayed randomly are already defined in my colors.xml file

Any Guidance or a lead sample on this requirement will be invaluable.

Thank you in advance

olasammy
  • 6,676
  • 4
  • 26
  • 32
  • You question is way to brood to give straight answer. Basically what you are asking here is how to create android app. You app involves user input, arrays or lists, changing view color, asynchronous functions, using random values. You need to give a specific question - like "How to load color values in spinner or listview ?" – somerandomusername Feb 07 '17 at 12:42
  • You are probably correct. So to refine the question, what I am planning to do is to randomly display various color based on a particular color a user selects. – olasammy Feb 08 '17 at 06:55

1 Answers1

0
 private int[] colors = {Color.RED, Color.YELLOW, Color.BLUE, Color.CYAN, Color.GREEN};

 Random ranndom = new Random();
 int ranndomColor = ranndom.nextInt(5);
 whatever.setBackground(colors[ranndomColor]);

or get the colors from "colors.xml:

int color1 = getResources().getColor(R.color.color1);
int color2 = getResources().getColor(R.color.color2);
int color3 = getResources().getColor(R.color.color3);
int color4 = getResources().getColor(R.color.color4);
int color5 = getResources().getColor(R.color.color5);

 private int[] colors = {color1, color2, color3, color4, color5};

 Random ranndom = new Random();
 int ranndomColor = ranndom.nextInt(5);
 whatever.setBackground(colors[ranndomColor]);
Ofek Ashery
  • 86
  • 1
  • 3