Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8670779
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 12, 20262026-06-12T18:47:17+00:00 2026-06-12T18:47:17+00:00

I need to make a layout background flash or blink, changing every second. I

  • 0

I need to make a layout background flash or blink, changing every second. I wrote this code:

int colours[]={0xff00ff00, 0xffff0000, 0xff0000ff,0xffffffff};
RelativeLayout fondo;

@Override
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    fondo = (RelativeLayout) findViewById(R.id.fondo);
    this.fondo.setBackgroundColor(colours[0]);
    this.fondo.setOnTouchListener(this);
}

Here is the onTouch method:

public boolean onTouch(View v, MotionEvent event) {
    if(event.getAction() == MotionEvent.ACTION_UP) {
        int i=1;
        long delay= 1000;
        long time = System.currentTimeMillis();

        while(true) {
            long time2 = System.currentTimeMillis();
            long time3 = (time2 - time);
            if (time3 > delay) {
                this.fondo.setBackgroundColor(colours[i]);
                Log.d("DEBUG", "EEEEEEEEEEEEEEEEEEEEEEEEEEEEE");
                time = System.currentTimeMillis();
                i++;
                if (i >= colores.length)
                    i=0;
            }
        }
    }
    return true;
}

My problem is that I can’t change the background color every second, but I can write the Log.d(“DEBUG”) every second.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-12T18:47:18+00:00Added an answer on June 12, 2026 at 6:47 pm

    You should use AnimationDrawable.

    If you use an infinite loop in a UI Thread it causes ANR (Android Not Responding) Window

       public boolean onTouch(View v, MotionEvent event) {
    
            final int DELAY = 100;
    
            if(event.getAction() == MotionEvent.ACTION_UP) {
    
    
                RelativeLayout fondo = (RelativeLayout) findViewById(R.id.fondo);
    
                ColorDrawable f = new ColorDrawable(0xff00ff00);
                ColorDrawable f2 = new ColorDrawable(0xffff0000);
                ColorDrawable f3 = new ColorDrawable(0xff0000ff);
                ColorDrawable f4 = new ColorDrawable(0xff0000ff);
    
                AnimationDrawable a = new AnimationDrawable();
                a.addFrame(f, DELAY);
                a.addFrame(f2, DELAY);
                a.addFrame(f3, DELAY);
                a.addFrame(f4, DELAY);
                a.setOneShot(false);
    
                fondo.setBackgroundDrawable(a); // This method is deprecated in API 16
                // fondo.setBackground(a); // Use this method if you're using API 16
                a.start();
             }
             return true;
        }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I need to make an android layout like this one. tile background all over
I need to make a layout that looks like this: [250px - fixed div]
i need help on how to make fixed textview size in table layout. say
I'm trying to make a force directed graph using d3.layout.force , and I need
I need to make a ul that changes background colors in groups of 4
I need make layout that must look exactly like below 2 sites. How should
I need to make rounded inputs with inner lighting like on this picture: I
Below is the simple layout. I need help with this because when I scaling
I want to know, what's the best structure to make this layout with pure
here is the layout http://timsegreto.com/cssmock/mock.html i need the background image to scroll concordant with

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.