Is there a way to disable ActionBar's show/hide animation?

前端 未结 3 467
一整个雨季
一整个雨季 2020-12-17 18:06

I\'ve seen this question:

Changing the ActionBar hide animation?

But it doesn\'t say whether it\'s possible to disable animation altogether.

相关标签:
3条回答
  • 2020-12-17 18:43

    I fixed using the below method:

    public static void disableShowHideAnimation(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);
            }catch (Exception e){
                //....
            }
        }
    }
    
    0 讨论(0)
  • 2020-12-17 18:53

    You can now do this,

    getSupportActionBar().setShowHideAnimationEnabled(false);
    
    0 讨论(0)
  • 2020-12-17 18:58

    If you use ActionBarSherlock then you can do it. See ActionBarImpl class, it has setShowHideAnimationEnabled(boolean enabled) method.

    0 讨论(0)
提交回复
热议问题