You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I was trying to set a selectableBackroundCompat on a Item, but I noticed that using that mehtod, when you click on the view no effect is shown on API < 21
I saw that, for API < 21, you're calling the following utility method inside DrawableUtils:
public static Drawable getSelectableBackgroundCompat(@ColorInt int normalColor, @ColorInt int pressedColor, @ColorInt int rippleColor) {
return (Drawable)(Utils.hasLollipop()?new RippleDrawable(ColorStateList.valueOf(rippleColor), getStateListDrawable(normalColor, pressedColor), getRippleMask(normalColor)):getStateListDrawable(normalColor, pressedColor));
}
...
private static StateListDrawable getStateListDrawable(@ColorInt int normalColor, @ColorInt int pressedColor) {
StateListDrawable states = new StateListDrawable();
states.addState(new int[]{16843518}, getColorDrawable(pressedColor));
states.addState(new int[0], getColorDrawable(normalColor));
if(!Utils.hasLollipop() || Utils.hasNougat()) {
short duration = 200;
states.setEnterFadeDuration(duration);
states.setExitFadeDuration(duration);
}
return states;
}
I saw that 16843518 corresponds to state_activated.
I think that ONLY for API < 21 you should add also the state_pressed.
You could replace the call to getStateListDrawable, with a new getStateListDrawableLegacy, like this one:
public static Drawable getSelectableBackgroundCompat(@ColorInt int normalColor, @ColorInt int pressedColor, @ColorInt int rippleColor) {
return (Drawable)(Utils.hasLollipop()?new RippleDrawable(ColorStateList.valueOf(rippleColor), getStateListDrawable(normalColor, pressedColor), getRippleMask(normalColor)):getStateListDrawableLegacy(normalColor, pressedColor));
}
..
private static StateListDrawable getStateListDrawableLegacy(@ColorInt int normalColor, @ColorInt int pressedColor) {
StateListDrawable states = new StateListDrawable();
states.addState(new int[]{16843518}, getColorDrawable(pressedColor));
states.addState(new int[]{16842919}, getColorDrawable(pressedColor));
states.addState(new int[0], getColorDrawable(normalColor));
if(!Utils.hasLollipop() || Utils.hasNougat()) {
short duration = 200;
states.setEnterFadeDuration(duration);
states.setExitFadeDuration(duration);
}
return states;
}
I tested it and it works fine ob both 6.0.1 or 4.1 Android versions.
Thanks & Regards
The text was updated successfully, but these errors were encountered:
Hi,
I was trying to set a selectableBackroundCompat on a Item, but I noticed that using that mehtod, when you click on the view no effect is shown on API < 21
I saw that, for API < 21, you're calling the following utility method inside DrawableUtils:
I saw that 16843518 corresponds to state_activated.
I think that ONLY for API < 21 you should add also the state_pressed.
You could replace the call to getStateListDrawable, with a new getStateListDrawableLegacy, like this one:
I tested it and it works fine ob both 6.0.1 or 4.1 Android versions.
Thanks & Regards
The text was updated successfully, but these errors were encountered: