3

is it possible to animate a system alert type view? if it's how?

I tried this but it didn't work:

public void onCreate(Bundle savedInstanceState)
{
    super.onCreate(savedInstanceState);
    setContentView(R.layout.main);

    View view = new View(this);
    view.setBackgroundColor(0x33FF0000);
    Animation animation = AnimationUtils.loadAnimation(this, R.anim.blink);
    view.startAnimation(animation);


    WindowManager windowManager = (WindowManager) getSystemService(Context.WINDOW_SERVICE);
    WindowManager.LayoutParams layoutParams = new WindowManager.LayoutParams(-1, -1, 2006, 1336, -3);
    windowManager.addView(view, layoutParams);
}

blink.xml:

<alpha
    android:interpolator="@android:anim/accelerate_decelerate_interpolator"
    android:fromAlpha="0.0"
    android:toAlpha="1"
    android:duration="500"
    android:repeatMode="reverse"
    android:repeatCount="9999999"/>

This code adds the view to the system but it's not animated.

Ali
  • 21,572
  • 15
  • 83
  • 95

1 Answers1

11

I found a solution for this:

the view which is going to be animated must not be directly added to the top window, because top window of android is not a real ViewGroup. so the view must be added to a ViewGroup like FrameLayout first and then this ViewGroup be added to the top window.

Ali
  • 21,572
  • 15
  • 83
  • 95
  • Thank you so much it did work. Could you please explain why did this work? – Sushant Mar 16 '16 at 06:38
  • @Sushant you're welcome, I pointed out why, because the most top window in android is not a view group and can't animate its children! – Ali Mar 16 '16 at 07:29