Created
June 25, 2015 14:00
-
-
Save fpezzato/8e7d45112883dbbc5ffb to your computer and use it in GitHub Desktop.
A CollapsingToolbarLayout that exposes private properties (ExpandedMargin so far)
This file contains hidden or 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
package org.fpezzato; | |
import android.content.Context; | |
import android.support.design.widget.CollapsingToolbarLayout; | |
import android.util.AttributeSet; | |
import com.google.common.base.Throwables; | |
import java.lang.reflect.Field; | |
/** | |
* Created by Francesco Pezzato on 25/06/2015. | |
* | |
* Experimental code - do *not* use in production! (or at your own risk - field reflection involved :/) | |
*/ | |
public class CustomCollapseToolbarLayout extends CollapsingToolbarLayout { | |
private Field mExpandedMarginLeft; | |
private Field mExpandedMarginTop; | |
private Field mExpandedMarginRight; | |
private Field mExpandedMarginBottom; | |
public CustomCollapseToolbarLayout(Context context) { | |
super(context); | |
} | |
public CustomCollapseToolbarLayout(Context context, AttributeSet attrs) { | |
super(context, attrs); | |
} | |
public CustomCollapseToolbarLayout(Context context, AttributeSet attrs, int defStyleAttr) { | |
super(context, attrs, defStyleAttr); | |
} | |
{ | |
try { | |
mExpandedMarginLeft = this.getClass().getSuperclass().getDeclaredField("mExpandedMarginLeft"); | |
mExpandedMarginLeft.setAccessible(true); | |
mExpandedMarginTop = this.getClass().getSuperclass().getDeclaredField("mExpandedMarginTop"); | |
mExpandedMarginTop.setAccessible(true); | |
mExpandedMarginRight = this.getClass().getSuperclass().getDeclaredField("mExpandedMarginRight"); | |
mExpandedMarginRight.setAccessible(true); | |
mExpandedMarginBottom = this.getClass().getSuperclass().getDeclaredField("mExpandedMarginBottom"); | |
mExpandedMarginBottom.setAccessible(true); | |
} catch (NoSuchFieldException e) { | |
throw Throwables.propagate(e); | |
} | |
} | |
public void setExpandedMarginLeft(int expandedMarginLeft) { | |
try { | |
mExpandedMarginLeft.setInt(this, expandedMarginLeft); | |
} catch (IllegalAccessException e) { | |
throw Throwables.propagate(e); | |
} | |
} | |
public void setExpandedMarginTop(int expandedMarginTop) { | |
try { | |
mExpandedMarginTop.setInt(this, expandedMarginTop); | |
} catch (IllegalAccessException e) { | |
throw Throwables.propagate(e); | |
} | |
} | |
public void setExpandedMarginRight(int expandedMarginRight) { | |
try { | |
mExpandedMarginRight.setInt(this, expandedMarginRight); | |
} catch (IllegalAccessException e) { | |
throw Throwables.propagate(e); | |
} | |
} | |
public void setExpandedMarginBottom(int expandedMarginBottom) { | |
try { | |
mExpandedMarginBottom.setInt(this, expandedMarginBottom); | |
} catch (IllegalAccessException e) { | |
throw Throwables.propagate(e); | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment