fitsSystemWindows effect gone for fragments added via FragmentTransaction

前端 未结 6 1040

I have an Activity with navigation drawer and full-bleed Fragment (with image in the top that must appear behind translucent system bar on Lollipop). While I had an interim

6条回答
  •  庸人自扰
    2020-11-28 03:07

    The other horrendous problem with dispatching of Window insets is that the first View to consume window insets in a depth-first search prevents all other views in the heirarchy from seeing window insets.

    The following code fragment allows more than one child to handle window insets. Extremely useful if you're trying to apply windows insets to decorations outside a NavigationView (or CoordinatorLayout). Override in the ViewGroup of your choice.

    @Override
    public WindowInsets dispatchApplyWindowInsets(WindowInsets insets) {
        if (!insets.isConsumed()) {
    
            // each child gets a fresh set of window insets
            // to consume.
            final int count = getChildCount();
            for (int i = 0; i < count; i++) {
                WindowInsets freshInsets = new WindowInsets(insets);
                getChildAt(i).dispatchApplyWindowInsets(freshInsets);
            }
        }
        return insets; // and we don't.
    }
    

    Also useful:

    @Override
    public WindowInsets dispatchApplyWindowInsets(WindowInsets insets) {
          return insets.consume(); // consume without adding padding!
    }
    

    which allows plain ordinary Views that are children of this view to be laid out without window insets.

提交回复
热议问题