Phil Kulak
Phil Kulak

Reputation: 7220

fitSystemWindows is never being called

I've got a view that needs to be anchored to the bottom of the screen. In fullscreen it needs to be at the very bottom, but during temporary non-fullscreen (on user taps) it needs to move up to not be hidden by the system bar. The docs say that setting android:fitsSystemWindows=true should do the trick. Or you could even override fitSystemWindows to get the new bounds and apply the margin yourself.

The problem is that this method is never called, so the property doesn't work either and there doesn't seem to be anything I can do. It looks like fitSystemWindows on ActionBarOverlayLayout is the culprit: it's returning true from it's method at all times, which seems to then be canceling the propagation of that method to any other views in the tree. But, that's a system class and it doesn't look like there much I can do to get it to stop doing that apart from possibly removing the actionbar completely.

I know I have to be missing something. Can only one view ever be set to avoid being trampled by the system components? This is just a video player, and I've seen plenty of other video players that don't seem to have this problem. Thanks for any help!

Upvotes: 4

Views: 1026

Answers (1)

Phil Kulak
Phil Kulak

Reputation: 7220

The problem here is that the default implementation of fitSystemWindows swallows the event for all children and when you use a overlay ActionBar, your entire view hierarchy then sits below a view that is swallowing the event you need. There's nothing you can do except not use an ActionBar, unfortunately.

Then you have to keep in mind that the default fitSystemWindows (defined on ViewGroup) also swallows the event for all siblings! So, if you want sibling views to avoid the system windows, you need to write your own fitSystemWindows and make sure you always return false so that the event will propagate to other views that may need it.

I understand why Google would not send the event to children (since the insets are an absolute position and if a parent view has repositioned itself, children no longer need to worry about it), but dropping it on the floor for all sibling views has got to a be a bug.

Upvotes: 2

Related Questions