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

  • Home
  • SEARCH
  • 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 8839909
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 14, 20262026-06-14T10:20:40+00:00 2026-06-14T10:20:40+00:00

I have a checkbox that should look like a green light when checked and

  • 0

I have a checkbox that should look like a green light when checked and a red blinking light when unchecked. To do this I created a selector called connected_selector.xml.

<?xml version="1.0" encoding="utf-8"?>
<selector
  xmlns:android="http://schemas.android.com/apk/res/android">
    <item android:state_checked="true" android:drawable="@drawable/green_button" />
    <item android:state_checked="false" android:drawable="@drawable/red_button_blinking" />
    <item android:drawable="@drawable/red_button_blinking" />
</selector>

The green_button is simply a png and the red_button_blinking is an animation-list of pngs.

<?xml version="1.0" encoding="utf-8"?>
<animation-list
  xmlns:android="http://schemas.android.com/apk/res/android" android:oneshot="false">
    <item android:drawable="@drawable/red_button" android:duration="500" />
    <item android:drawable="@drawable/red_button_lit" android:duration="500" />
</animation-list>

The checkbox’s background is set to @drawable/connected_selector. If the checkbox is initially unchecked, it doesn’t blink, it just shows the @drawable/red_button. However if I check the box and then uncheck it, the checkbox will animate correctly.

How can I make the animation start initially since the checkbox will be initially unchecked? I guess I could try to start the animation manually in code, but I don’t think that should be necessary.

  • 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-14T10:20:41+00:00Added an answer on June 14, 2026 at 10:20 am

    Okay, I found an ugly, dirty hack to get around this. Note that I don’t have the slightest clue why this happens, just a way around this. It is probably not even a generic way since different devices will have different loading times.

    I execute the following workaround in onPostResume() to minimize the necessary delay time.

    if(onOffStatus) {
        // SLEEP 0.5 SECONDS HERE ...
        new Handler().postDelayed(new Runnable() { 
            public void run() {
                switcher.setBackgroundResource(R.drawable.button_state_anim);
    
                // Get the background, which has been compiled to an AnimationDrawable object.
                AnimationDrawable frameAnimation = (AnimationDrawable) switcher.getBackground();
                // Start the animation (looped playback by default).
                frameAnimation.start();
            } 
        }, 500); // Actual required time will probably be dependent on device performance
    }
    

    It ain’t pretty but I’m going with this until I find something better. Let me know if I overlooked something here.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

In my html.beginform I have this checkbox that I want to persist. I'm not
I would like to have a checkbox preference that takes the user to a
I have a .NET application that contains a checkbox (System.Windows.Forms.Checkbox). This component (WindowsForms10.BUTTON.app.0.378734a1) is
I have a list of checkboxes that look like below, the numbers, 416, 419,
I have a checkbox that I do not want the user to have direct
I have a checkbox that when it is clicked it submits the form to
I am trying to create my own Native win32 C++ Checkbox that can have
I have a CheckBox in my application that is using the TriState mode. The
i have disabled all the checkboxes except one. On click of that checkbox i
I have datagridview with checkbox column, but I want, that some of the columns

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.