Created
April 14, 2017 07:35
-
-
Save g4s8/29d9c1342a690ddfc865ce31dbc5beaa to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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