0

I apologise if this question is not clear, I think it is hard to explain what I am imagining.

I have seen this question: android - How can I make a button flash?

I believe that is the closest to what I'm trying to achieve. It appears that the button is fading in and out to simulate a fading/flashing effect.

My question is, how do I define the colours to have it fade in and out to? My button is currently grey, but I'd like it to fade in and out from grey to light green and back again (to draw attention to the button when a certain event gets fired).

If anyone could see where you could define colours in that code, I would sure appreciate it.

Thanks

Community
  • 1
  • 1
b85411
  • 9,420
  • 15
  • 65
  • 119

1 Answers1

0

try this:

    @Override
    protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    requestWindowFeature(Window.FEATURE_NO_TITLE);
    getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN,
            WindowManager.LayoutParams.FLAG_FULLSCREEN);
    setContentView(R.layout.splash);
    colorr();
        }



public void colorr() {
    final Handler handler = new Handler();
    new Thread(new Runnable() {

        @Override
        public void run() {
            try {
                Thread.sleep(1000);
            } catch (InterruptedException e) {
                e.printStackTrace();
            }
            handler.post(new Runnable() {

                @Override
                public void run() {

                    button = (Button) findViewById(R.id.button);
                    if (button.getText().equals("HAI")) {
                        button.setBackgroundColor(Color.GREEN);
                    }
                    colorr1();
                }
            });
        }
    }).start();
}
public void colorr1() {
    final Handler handler = new Handler();
    new Thread(new Runnable() {

        @Override
        public void run() {
            try {
                Thread.sleep(1000);
            } catch (InterruptedException e) {
                e.printStackTrace();
            }
            handler.post(new Runnable() {

                @Override
                public void run() {

                    button = (Button) findViewById(R.id.button);
                    if (button.getText().equals("HAI")) {
                        button.setBackgroundColor(Color.BLUE);
                    }
                    colorr();
                }
            });
        }
    }).start();
}

}

pooja
  • 71
  • 3