I will just add this here if someone needs to remove the top add-on when using fitSystemWindows. This can occur when using custom action bars, DrawerLayout / NavigationView and / or fragments.
public class CustomFrameLayout extends FrameLayout { public CustomFrameLayout(Context context) { super(context); } public CustomFrameLayout(Context context, AttributeSet attrs) { super(context, attrs); } public CustomFrameLayout(Context context, AttributeSet attrs, int defStyleAttr) { super(context, attrs, defStyleAttr); } @TargetApi(Build.VERSION_CODES.LOLLIPOP) public CustomFrameLayout(Context context, AttributeSet attrs, int defStyleAttr, int defStyleRes) { super(context, attrs, defStyleAttr, defStyleRes); } @Override protected boolean fitSystemWindows(Rect insets) {
We need to extend the Layout class (FrameLayout in my case) and remove the top padding in fitSystemWindows() (for API <20) or onApplyWindowInsets() (for API> = 20).
source share