I have SingleFramgnetActivity
whose purpose is only to hold and replace fragments inside it.
layout looks like this:
You could also build a custom WindowInsetsFrameLayout
and use a OnHierarchyChangedListener
to request applying the insets again:
public WindowInsetsFrameLayout(Context context, AttributeSet attrs, int defStyleAttr) {
super(context, attrs, defStyleAttr);
// Look for replaced fragments and apply the insets again.
setOnHierarchyChangeListener(new OnHierarchyChangeListener() {
@Override
public void onChildViewAdded(View parent, View child) {
requestApplyInsets();
}
@Override
public void onChildViewRemoved(View parent, View child) {
}
});
}
Check out this detailed answer: https://stackoverflow.com/a/47349880/3979479