Skip to content

Instantly share code, notes, and snippets.

@MohammadAG
Created July 2, 2014 16:33
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save MohammadAG/3503e08deac416a3b71a to your computer and use it in GitHub Desktop.
Save MohammadAG/3503e08deac416a3b71a to your computer and use it in GitHub Desktop.
Setting RippleDrawable manually
// To instantiate a RippleDrawable:
// new RippleDrawable(null, null), the default constructor isn't public.
// Unfortunately, this has no colors set, so the app will crash, here's another way
int[] attrs = new int[] { android.R.attr.selectableItemBackground};
TypedArray array = getContext().obtainStyledAttributes(attrs);
Drawable drawableFromTheme = array.getDrawable(0);
array.recycle();
setBackground(drawableFromTheme);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment