15

I've seen this question:

Changing the ActionBar hide animation?

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

Community
  • 1
  • 1
Violet Giraffe
  • 32,368
  • 48
  • 194
  • 335

3 Answers3

29

You can now do this,

getSupportActionBar().setShowHideAnimationEnabled(false);
Tyler Pfaff
  • 4,900
  • 9
  • 47
  • 62
16

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){
            //....
        }
    }
}
Kani
  • 179
  • 1
  • 4
  • Using private methods is not a very good idea, it will probably get broken in the future. Apple doesn't even allow apps using private methods in the app store. – Miloš Černilovský Feb 04 '15 at 12:54
  • 5
    @MilošČernilovský Using Android is a bad idea. It's full of bugs and limitations. But I still prefer to hack this hack of an operating system rather than implement things from scratch – Alexandre G May 12 '16 at 06:06
4

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

user1275972
  • 131
  • 1
  • 8