Is there a way to disable ActionBar's show/hid

2019-01-25 11:13发布

I've seen this question:

Changing the ActionBar hide animation?

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

3条回答
我命由我不由天
2楼-- · 2019-01-25 11:56

You can now do this,

        getSupportActionBar().setShowHideAnimationEnabled(false);
查看更多
手持菜刀,她持情操
3楼-- · 2019-01-25 12:05

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){
            //....
        }
    }
}
查看更多
唯我独甜
4楼-- · 2019-01-25 12:05

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

查看更多
登录 后发表回答