Android: Set Random colour background on create

后端 未结 6 1616
既然无缘
既然无缘 2020-12-09 11:38

What I want is when I load my app up it to randomly have a certain colored background from a predefined list of strings stored in a values xml file called colours.

6条回答
  •  感情败类
    2020-12-09 12:25

    There's a much better answer than the ones provided.

    If you want a Truly random color, "randomly" choosing from a res file doesn't prove to be nearly as robust.

    Instead, use this code snippet:

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

提交回复
热议问题