0

My Problem is:

If you show and hide the ActionBar multiple times maybe you have noticed that the first showing is not animated. From then on showing and hiding are animated.

My issue is described described in this stackoverflow thread, in the section refereed to as ADDON (This thread does not solve my problem) - stackoverflow.com/a/14167949/4424557 - I am not facing the same issue as this user, although the point made by the answerer explains my issue

How do I fix the above, so that even the first time it is revealed animation does take place?

To explain the animation I'm referring to -

Look at this youtube clip

https://www.youtube.com/watch?v=6gZ_y7MqEGM

(The animation above works, but in my case on primary reveal the animation doesn't occur)

The code I'm using to reveal the actionbar is below:

android.support.v7.app.ActionBar actionBar;
            actionBar = getSupportActionBar();
            actionBar = getSupportActionBar();
            actionBar.setDisplayShowTitleEnabled(false);
            actionBar.setDisplayUseLogoEnabled(false);
            actionBar.setDisplayHomeAsUpEnabled(false);


            LayoutInflater mInflater = LayoutInflater.from(this);
            View mCustomView = mInflater.inflate(R.layout.custom_actionbar, null);

            actionBar.setCustomView(mCustomView);
            actionBar.setDisplayShowCustomEnabled(true);

actionBar.hide();

Or

actionBar.show();
Community
  • 1
  • 1
  • i don't know what animation you mean, but it sounds like the animation occurs when its hidden. cant you create the ActionBar when you actually need it? – Bart Hofma Jan 20 '15 at 09:21
  • 2
    I've updated the question above, to show a youtube clip explaining this. I reveal and hide when I need it. –  Jan 20 '15 at 09:29
  • does this help you? invalidateOptionsMenu(); – Bart Hofma Jan 20 '15 at 09:46
  • No, I've placed the above suggested code prior to each actionBar.hide(); or actionBar.show(); and the issue still occurs –  Jan 20 '15 at 09:50
  • i think it should go right AFTER show(); – Bart Hofma Jan 20 '15 at 09:53
  • Just tried that too. Issue still occurs –  Jan 20 '15 at 09:54
  • Just to clarify, the animation DOES happen, only when it does, your actionbar is hidden, so you don't see it. You have to find a way to recreate this actionbar, or make what you are trying to do a new activity(which you probably should, but i might be wrong) – Bart Hofma Jan 20 '15 at 09:59
  • No, when the actionbar is first revealed (actionbar.show()), there is no animation happening. - Which is the problem. After this first reveal animation does work. But the first time it doesn't –  Jan 20 '15 at 10:05
  • did you try putting hide and show right after eachother? – Bart Hofma Jan 20 '15 at 10:11
  • I have and similarly in that case, the first time the actionbar is revealed there is no animation –  Jan 20 '15 at 10:13
  • btw, i can't see it in your video, because in the video the animation happens everytime. Its already there when the video starts, so i cant see the animation not happening – Bart Hofma Jan 20 '15 at 10:16
  • It's not my video, it was one I found on Youtube showing what animation I'm refering to. –  Jan 20 '15 at 10:17
  • and when it DOES happen you are using show(); ? – Bart Hofma Jan 20 '15 at 10:19
  • 1
    Yes, as similarly described in this stackoverflow thread, in the section refereed to as ADDON (This thread does not solve my problem) - http://stackoverflow.com/a/14167949/4424557 - I am not facing the same issue as this user, although the point made by the answerer explains my issue –  Jan 20 '15 at 10:33
  • thanks for explaining, you might want to edit your question with the information you have gathered so far so others don't have to browse through the comments – Bart Hofma Jan 20 '15 at 10:38
  • I have, after having read that thread. Do you now have any idea, for how to solve my issue? –  Jan 20 '15 at 10:56

1 Answers1

0

Simply using the hide or show functions does what it says, but will NOT 'animate' it. In order to do so you could use a Interpolator.

I'd suggest you use the new Toolbar. Its really easy! ActionBar is now deprecated. With a toolbar you could do it like:

on Show:

toolbar.animate().translation(0).setInterpolator(new DecelerateInterpolator(2)).start();

on Hide:

toolbar.animate().translationY(-mToolbarHeight).setInterpolator(new AccelerateInterpolator(2)).start();

Personally, I've done a similar implementation for a Floating Action Button (FAB) here by using a custom ScrollListener. The same can be modified for Toolbar.

PS: What you're trying to achieve is also known as the Quick Return Pattern.

Suleiman19
  • 742
  • 1
  • 7
  • 21