samedi 7 janvier 2017

How to generate different color than last time

In colors.xml I have this Array:

<item name="purple" type="color">#FFAA66CC</item>
<item name="red" type="color">#FFFF4444</item>
<item name="darkpurple" type="color">#FF9933CC</item>
<item name="darkred" type="color">#FFCC0000</item>

<integer-array name="androidcolors">
    <item>@color/purple</item>
    <item>@color/red</item>
    <item>@color/darkpurple</item>
    <item>@color/darkred</item>
</integer-array>

I generate random color with,

int[] androidColors = getResources().getIntArray(R.array.androidcolors);
int randomAndroidColor = androidColors[new Random().nextInt(androidColors.length)];
button1.setBackgroundColor(randomAndroidColor);

It works good but sometimes it generates the same as last time. How can I fix this?




Aucun commentaire:

Enregistrer un commentaire