导航抽屉 onDrawerSlide 改变 Alpha Api 11

Navigation Drawer onDrawerSlide change Alpha Api 11

我想在导航抽屉打开时设置工具栏的 Alpha,并在它关闭时重置它。在 Api 低于 11 时 .setAlpha 不起作用。我试过了:

 public void onDrawerSlide(View drawerView, float slideOffset) {
            if (Build.VERSION.SDK_INT < 11) {
                final AlphaAnimation animation = new AlphaAnimation(1 - slideOffset, 0.6f);
                animation.setDuration(0);
                animation.setFillAfter(true);
                toolbar.startAnimation(animation);
            } else if (slideOffset < 0.6) {
                toolbar.setAlpha(1 - slideOffset);
            }
        }

在 Andorid 5.0 上一切正常。但是如果我在 Android 2.3 上关闭 NavDrawer,alpha 不会被重置。

just do add the following line in onDrawerClosed function 

toolbar.clearAnimation();


@Override

 public void onDrawerClosed(View drawerView) {``
                super.onDrawerClosed(drawerView);
                getActivity().supportInvalidateOptionsMenu();
                toolbar.clearAnimation();
            }