Animation actionBar material design

2019-03-16 18:55发布

问题:

how you can do this kind of animations in the ActionBar?

Example animation actionBar material design

回答1:

Currently there isn't public API to obtain this.

You can try this library:

https://github.com/markushi/android-ui



回答2:

I have used balysv/material-menu library and implemented successfully.

ActionView By Markushi requires API level 14+ but material-menu by balysv can be used with ActionBarSherLock also with animation customization.

Here you have four icon states:

BURGER, ARROW, X, CHECK. You can use (X, CHECK) for delete operation and (BURGER, ARROW) for navigation drawer.

One more feature that i like is pressed circle animation. Here we have choice between pressed circle animation and non-pressed circle animation.

You can have full control of animation while sliding a drawer like this,



回答3:

Android Support Library v7's ActionBarDrawerToggle has that animation.

https://developer.android.com/reference/android/support/v7/app/ActionBarDrawerToggle.html

Here is the instruction to add support library v7 to your project. https://developer.android.com/tools/support-library/setup.html



回答4:

In addition to Gabriele Mariotti's answer.

You might try to replace android.R.id.home with the ActionView from the library he mentioned.

Find the view and replace it:

private void replaceHomeView(Activity activity){
    View homeView;
    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.HONEYCOMB) {
            Resources resources = activity.getResources();
            int id = resources.getIdentifier("android:id/home", null, null);
            homeView = activity.getWindow().getDecorView().findViewById(id);
        } else {
            homeView = activity.getWindow().getDecorView().findViewById(R.id.home);
        }
    replace(homeView);

}

Remove and replace home icon ImageView:

private replace(View home){
   ViewGroup parent = (ViewGroup) view.getParent();
   int homeIndex = parent.indexOfChild(view);
   ActionView newHome = new ActionView(home.getContext));
   newHome.setId(home.getId());
   parent.removeView(home);
   parent.addView(newHome, homeIndex);
}

Note: I haven't tested this myself.