Answer the question
In order to leave comments, you need to log in
How to make "constantly" changing background color in android studio on button click?
Actually, here is the button code that starts changing our background to a random color
public void onRdmButtonClick(View view) {
int x=0;
Random rand = new Random();
while(x<5) {
mRelativeLayout.setBackgroundColor(-rand.nextInt(0xFFFFFF));
x++;
}
}
Answer the question
In order to leave comments, you need to log in
Well, I think that everything is changing for itself, maybe even randomly, but you just don’t have time to see it. There is no delay in the cycle. It will end in ten machine cycles, which is less than the human eye can see. The easiest option is to insert sleep. But since this is most likely your main UI thread, then you can’t do this in production - you need to create a separate thread so as not to freeze the interface thread.
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question