Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Animate system alert type view

Tags:

android

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.

like image 586
Ali Avatar asked Jun 13 '26 15:06

Ali


1 Answers

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.

like image 94
Ali Avatar answered Jun 15 '26 06:06

Ali