1

I am trying to see if it is possible to create an observable, that would notify when action bar visibility changes.

Something in a way of

LiveData<Boolean> actionBarVisibility;

So that other UI can be updated when actionBar is shown/hidden? I found this little trick to identify the view visibility change events, but cannot figure out how to apply it to actionBar, since its view is not accessible to me.

Paul
  • 1,879
  • 1
  • 23
  • 44

1 Answers1

0

Yes, you can observe the state of Boolean!

Inside ViewModel

var isActionBarVisible: MutableLiveData<Boolean> = MutableLiveData()

set visibility

isActionBarVisible.postValue(true)

set invisibility

isActionBarVisible.postValue(false)

====

Inside View (Activity or Fragment)

viewProvider!!.isActionBarVisible.observe(this, Observer {
        if (it!!) {
            // on visible of action bar
        } else {
           // on invisible of action bar
        }
    })
Kishore Jethava
  • 6,666
  • 5
  • 35
  • 51
  • 2
    I am sorry, but that is not the question I asked - observing a boolean is simple, I agree, how do I hook into ActionBar of an activity, to update that value when visibility actually changes? – Paul Feb 09 '19 at 00:23