Skip to content

Instantly share code, notes, and snippets.



Last active Mar 11, 2016
What would you like to do?
RxAppBarLayout for observing AppBarLayout vertical offset
import rx.Observable;
import rx.Subscriber;
import rx.Subscription;
* Helper class for creating Observable of AppBarLayout visibility.
* Can be easily modified to return Integer values, if one needs to user verticalOffset param directly.
* See for further info:
public final class RxAppBarLayout {
public static Observable<Boolean> appBarVisibility(AppBarLayout appBarLayout) {
return Observable.create(new AppBarLayoutStateOnSubscribe(appBarLayout));
private static class AppBarLayoutStateOnSubscribe implements Observable.OnSubscribe<Boolean> {
private final appBarLayout;
private Boolean mAppBarVisible = true;
private AppBarLayoutStateOnSubscribe(AppBarLayout appBarLayout) {
this.appBarLayout = appBarLayout;
public void call(Subscriber<? super Boolean> subscriber) {
AppBarLayout.OnOffsetChangedListener listener = new AppBarLayout.OnOffsetChangedListener() {
public void onOffsetChanged(AppBarLayout appBarLayout, int verticalOffset) {
mAppBarVisible = verticalOffset == 0;
subscriber.add(new Subscription() {
public void unsubscribe() {
public boolean isUnsubscribed() {
return false;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.