How can I Animate the color change of the statusbar and toolbar (like the new Calendar app does)

前端 未结 4 1620
逝去的感伤
逝去的感伤 2021-01-29 22:49

The new Google Calendar app has an animation I would like to do in my app. When you create a new event you can choose a color for the event. When you do, the statusbar and too

4条回答
  •  再見小時候
    2021-01-29 23:13

    Try this, it works great for me and it gets the same effect Google Calendar app does.

    private void reveal(CollapsingToolbarLayout toolbarLayout, int colorPrimary, int colorPrimaryDark){
        // get the center for the clipping circle
        int cx = toolbarLayout.getWidth() / 2;
        int cy = toolbarLayout.getHeight() / 2;
    
        // get the final radius for the clipping circle
        float finalRadius = (float) Math.hypot(cx, cy);
    
        // create the animator for this view (the start radius is zero)
        Animator anim =
                ViewAnimationUtils.createCircularReveal(toolbarLayout, cx, cy, 0, finalRadius);
    
        // make the view visible and start the animation
        toolbarLayout.setBackgroundColor(colorPrimary);
        anim.start();
        Window window = getWindow();
        window.setStatusBarColor(colorPrimaryDark);
        toolbarLayout.setContentScrimColor(colorPrimary);
    }
    

提交回复
热议问题