Skip to content

Instantly share code, notes, and snippets.

@g4s8
Created April 14, 2017 07:35
Show Gist options
  • Save g4s8/29d9c1342a690ddfc865ce31dbc5beaa to your computer and use it in GitHub Desktop.
Save g4s8/29d9c1342a690ddfc865ce31dbc5beaa to your computer and use it in GitHub Desktop.
public class RootLayout extends android.widget.FrameLayout {
@Nullable
private WindowInsetsCompat windowInsets;
public RootLayout(Context context) {
this(context, null);
}
public RootLayout(Context context, AttributeSet attrs) {
this(context, attrs, 0);
}
public RootLayout(Context context, AttributeSet attrs, int defStyle) {
super(context, attrs, defStyle);
ViewCompat.setOnApplyWindowInsetsListener(this, (view, insets) -> {
windowInsets = new WindowInsetsCompat(insets);
return ViewCompat.onApplyWindowInsets(view, insets);
});
}
@Override
public void addView(@NonNull View child, int index, ViewGroup.LayoutParams params) {
super.addView(child, index, params);
if (windowInsets != null) {
ViewCompat.dispatchApplyWindowInsets(child, windowInsets);
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment