Skip to content Skip to sidebar Skip to footer

How To Get Color Of A Button With Ripple Drawable

I have variety of buttons and I would like to get their background color, getting background color in a color drawable is easy but it is not easy in ripple drawable, how can I mana

Solution 1:

Try this:

RippleDrawablerippleDrawable= (RippleDrawable) button.getBackground();
 Drawable.ConstantStatestate= rippleDrawable.getConstantState();
 try {
     FieldcolorField= state.getClass().getDeclaredField("mColor");
     colorField.setAccessible(true);
     ColorStateListcolorStateList= (ColorStateList) colorField.get(state);
     intrippleColor= colorStateList.getDefaultColor();
  } catch (NoSuchFieldException e) {
      e.printStackTrace();
  } catch (IllegalAccessException e) {
      e.printStackTrace();
  }

Solution 2:

The solution that I found was to remove entries from the manifest of a newly minted app - particularly look at styles, themes and colours - compare older working apps with the new one to determine suspects. The RippleDrawable then replaced itself with the ColorDrawable that it had been and .getColor() works again.

Solution 3:

please check following example for ripple effect in android..

http://www.viralandroid.com/2015/09/how-to-add-ripple-effect-to-android-button.html

Post a Comment for "How To Get Color Of A Button With Ripple Drawable"