Skip to content

Instantly share code, notes, and snippets.

@adam-hurwitz
Created August 23, 2017 05:05
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save adam-hurwitz/11f7693042d172bd74b9b1a596350c09 to your computer and use it in GitHub Desktop.
Save adam-hurwitz/11f7693042d172bd74b9b1a596350c09 to your computer and use it in GitHub Desktop.
Receive attributes in Custom View At Runtime.
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