Changing the ActionBar hide animation?

前端 未结 5 1368
滥情空心
滥情空心 2021-02-01 18:09

By default in Android 3.0+, when ActionBar.hide()/show() are called the bar is animated with a brief fade in/out animation.

There does not seem to be an XML style attri

5条回答
  •  醉梦人生
    2021-02-01 18:25

    if you use support-v7-compat, you can disable hide animation like this:

    @Override
    public boolean onCreateOptionsMenu(Menu menu) {
        //消除动画效果
        disableABCShowHideAnimation(getSupportActionBar());
        return super.onCreateOptionsMenu(menu);
    }
    
    
    
    public static void disableABCShowHideAnimation(ActionBar actionBar) {
        try
        {
            actionBar.getClass().getDeclaredMethod("setShowHideAnimationEnabled", boolean.class).invoke(actionBar, false);
        }
        catch (Exception exception)
        {
            try {
                Field mActionBarField = actionBar.getClass().getSuperclass().getDeclaredField("mActionBar");
                mActionBarField.setAccessible(true);
                Object icsActionBar = mActionBarField.get(actionBar);
                Field mShowHideAnimationEnabledField = icsActionBar.getClass().getDeclaredField("mShowHideAnimationEnabled");
                mShowHideAnimationEnabledField.setAccessible(true);
                mShowHideAnimationEnabledField.set(icsActionBar,false);
                Field mCurrentShowAnimField = icsActionBar.getClass().getDeclaredField("mCurrentShowAnim");
                mCurrentShowAnimField.setAccessible(true);
                mCurrentShowAnimField.set(icsActionBar,null);
                //icsActionBar.getClass().getDeclaredMethod("setShowHideAnimationEnabled", boolean.class).invoke(icsActionBar, false);
            }catch (Exception e){
                //....
            }
        }
    }
    

提交回复
热议问题