Created
March 30, 2017 13:04
-
-
Save Hackforid/1a86b5fcda14cdd896849ec4c9ccd3eb to your computer and use it in GitHub Desktop.
CompatCollapsingToolbarLayout
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 CompatCollapsingToolbarLayout extends CollapsingToolbarLayout { | |
private boolean mLayoutReady; | |
public CompatCollapsingToolbarLayout(Context context) { | |
this(context, null); | |
} | |
public CompatCollapsingToolbarLayout(Context context, AttributeSet attrs) { | |
this(context, attrs, 0); | |
} | |
public CompatCollapsingToolbarLayout(Context context, AttributeSet attrs, int defStyleAttr) { | |
super(context, attrs, defStyleAttr); | |
} | |
@Override | |
protected void onLayout(boolean changed, int left, int top, int right, int bottom) { | |
if (!mLayoutReady) { | |
if (Build.VERSION.SDK_INT > Build.VERSION_CODES.KITKAT) { | |
if ((getWindowSystemUiVisibility() & | |
(SYSTEM_UI_FLAG_LAYOUT_STABLE|SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN)) == | |
(SYSTEM_UI_FLAG_LAYOUT_STABLE|SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN)) { | |
try { | |
Field mLastInsets = CollapsingToolbarLayout.class.getDeclaredField("mLastInsets"); | |
mLastInsets.setAccessible(true); | |
mLastInsets.set(this, null); | |
} catch (NoSuchFieldException e) { | |
e.printStackTrace(); | |
} catch (IllegalAccessException e) { | |
e.printStackTrace(); | |
} | |
} | |
} | |
if (Build.VERSION.SDK_INT > Build.VERSION_CODES.LOLLIPOP) { | |
mLayoutReady = true; | |
} | |
} | |
super.onLayout(changed, left, top, right, bottom); | |
} | |
public void refix() { | |
if (Build.VERSION.SDK_INT > Build.VERSION_CODES.KITKAT) { | |
if ((getWindowSystemUiVisibility() & | |
(SYSTEM_UI_FLAG_LAYOUT_STABLE|SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN)) == | |
(SYSTEM_UI_FLAG_LAYOUT_STABLE|SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN)) { | |
try { | |
Field mLastInsets = CollapsingToolbarLayout.class.getDeclaredField("mLastInsets"); | |
mLastInsets.setAccessible(true); | |
mLastInsets.set(this, null); | |
} catch (NoSuchFieldException e) { | |
e.printStackTrace(); | |
} catch (IllegalAccessException e) { | |
e.printStackTrace(); | |
} | |
} | |
} | |
if (Build.VERSION.SDK_INT > Build.VERSION_CODES.LOLLIPOP) { | |
mLayoutReady = true; | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment