Open utterances-bot opened 3 years ago
First of all, thanks for posting such a helpful well-written article.
I'm having an issue though and hoped you could help. When I override with the onHideListener from the article, the FAB hides perfectly but calling performHide() or performShow() programmatically on the BottomAppBar no longer works. Any idea if there's a way to do this?
@JayDoogson Great question, this is because performHide()
and performShow()
use an inner state of Behavior
, at least in version 1.3.0 of Google Material library:
package com.google.android.material.bottomappbar;
/**/
public class BottomAppBar extends Toolbar implements AttachedBehavior {
/**/
private Behavior behavior;
/** Animates the {@link BottomAppBar} so it hides off the screen. */
public void performHide() {
getBehavior().slideDown(this);
}
/** Animates the {@link BottomAppBar} so it is shown on the screen. */
public void performShow() {
getBehavior().slideUp(this);
}
@NonNull
@Override
public Behavior getBehavior() {
if (behavior == null) {
behavior = new Behavior();
}
return behavior;
}
}
Unfortunately, there is no setter for this property, but you could probably extend the BottomAppBar
class replacing it in the layout XML, and override the getter with your own behavior. Otherwise, you could invoke the actions directly on the article's behavior as well:
behavior.slideUp(bottomAppBar); //bottomAppBar.performShow()
behavior.slideDown(bottomAppBar); //bottomAppBar.performHide()
BottomAppBar onHide listener
https://blog.termian.dev/posts/bottomappbar-onhide-listener/