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.
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.
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
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
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!!
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);
}
}
}
});
}