简体   繁体   中英

Android - fading/flashing button

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

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();
}

}

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM