Created
August 23, 2017 05:05
-
-
Save adam-hurwitz/11f7693042d172bd74b9b1a596350c09 to your computer and use it in GitHub Desktop.
Receive attributes in Custom View At Runtime.
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 RippleTextView(Context context) { | |
super(context); | |
//Retrieve attribute values at runtime | |
getXMLAttributes(context, null); | |
} | |
public RippleTextView(Context context, AttributeSet attrs) { | |
super(context, attrs); | |
//Retrieve attribute values at runtime | |
getXMLAttributes(context, attrs); | |
} | |
public RippleTextView(Context context, AttributeSet attrs, int defStyleAttr) { | |
super(context, attrs, defStyleAttr); | |
//Retrieve attribute values at runtime | |
getXMLAttributes(context, attrs); | |
} | |
private void getXMLAttributes(Context context, AttributeSet attrs) { | |
TypedArray typedArray = | |
context.getTheme().obtainStyledAttributes( | |
attrs, | |
R.styleable.RippleText, | |
0, | |
0); | |
try { | |
rippleEnabled = typedArray.getBoolean( | |
R.styleable.RippleText_rippleEnabled, | |
true); | |
backgroundColor = typedArray.getColor( | |
R.styleable.RippleText_backgroundColor, | |
getResources().getColor(R.color.ripple_default)); | |
rippleColor = typedArray.getColor( | |
R.styleable.RippleText_rippleColor, | |
getResources().getColor(R.color.ripple_default)); | |
} finally { | |
typedArray.recycle(); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment