1

i have button bar inside LinearLayout.

I want to warn the user by LinearLayout flashes some times.(like winking)

How do I do it?

Thank you in advance for your help.

shirin
  • 129
  • 1
  • 9

4 Answers4

0

you can do it by using a Thread with a sleep of whatever time you want and changing the background color of your linearLayout in it

1shubhamjoshi1
  • 546
  • 7
  • 16
  • I don't see why thread sleep is necessary. It will block the whole UI. But yes, the way is a background change... – Galya Mar 14 '16 at 17:00
0

LinearLayout is a View. That means you can use an animation to update the background of that view.

Here is an example: Animate change of view background color on Android

Community
  • 1
  • 1
Gennadii Saprykin
  • 4,505
  • 8
  • 31
  • 41
0

Just for fun...here is a tested sample using handler.postDelayed, flash for 5 seconds

    protected int seconds = 5;
    private LinearLayout llTest;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_flash);
        llTest= (LinearLayout ) findViewById(R.id.llTest);
        handler.removeCallbacks(runnable);
        handler.postDelayed(runnable, 1000);

    }

    private Runnable runnable = new Runnable() {
        public void run() {
            long currentMilliseconds = System.currentTimeMillis();
            seconds--;
            if (seconds > 0) {
                llTest.setBackgroundColor( seconds % 2 == 0 ? Color.RED : Color.BLUE );
                handler.postAtTime(this, currentMilliseconds);
                handler.postDelayed(runnable, 1000);
            } else {
                handler.removeCallbacks(runnable);                    
            }
        }
    };

Hope it helps!!

Gueorgui Obregon
  • 5,077
  • 3
  • 33
  • 57
0

I solve that by this method:

public void tintBackground(final View rootView, final boolean changeColor) {
    G.HANDLER.post(new Runnable() {

        @Override
        public void run() {
            int sdk = android.os.Build.VERSION.SDK_INT;
            if (changeColor) {
                ColorDrawable[] color = { new ColorDrawable(Color.RED),
                        new ColorDrawable(getResources().getColor(R.color.theme_color)) };
                TransitionDrawable trans = new TransitionDrawable(color);
                if (sdk < android.os.Build.VERSION_CODES.JELLY_BEAN) {
                    rootView.setBackgroundDrawable(trans);
                } else {
                    rootView.setBackground(trans);
                }
                trans.startTransition(1000); // do transition over 1 seconds
            } else {
                if (sdk < android.os.Build.VERSION_CODES.JELLY_BEAN) {
                    rootView.setBackgroundDrawable(null);
                } else {
                    rootView.setBackground(null);
                }
            }
        }
    });
}
shirin
  • 129
  • 1
  • 9