我创建了如下所示的RippleDrawable。但我不能改变RippleDrawable的拐角半径。它没有像setCornerRadii(float[] f)这样的方法。
public static RippleDrawable getPressedColorRippleDrawable(int normalColor, int pressedColor) {
if (Build.VERSION.SDK_INT>=21) {
RippleDrawable rippleDrawable = new RippleDrawable(getPressedColorSelector(normalColor, pressedColor), getColorDrawableFromColor(normalColor), null);
//rippleDrawable.setRadius((int) Manager.convertDpToPixel(5));
return rippleDrawable;
}
else
return null;
}其他的功能是
public static ColorStateList getPressedColorSelector(int normalColor, int pressedColor) {
return new ColorStateList(
new int[][]
{
new int[]{android.R.attr.state_pressed},
new int[]{android.R.attr.state_focused},
new int[]{android.R.attr.state_activated},
new int[]{}
},
new int[]
{
pressedColor,
pressedColor,
pressedColor,
normalColor
}
);
}
public static ColorDrawable getColorDrawableFromColor(int color) {
return new ColorDrawable(color);
}我该怎么做呢?
发布于 2019-04-01 16:00:59
我正面临着和你一样的问题:如何将拐角半径设置为RippleDrawable。
一种简单的处理方式是使用GradientDrawable。可以使用setCornerRadius设置radius,然后将配置的实例作为RippleDrawable构造函数的第二个参数传递。
下面是一个示例:
ColorStateList pressedStates = ColorStateList.valueOf(Color.BLUE);
GradientDrawable contentDrawable = new GradientDrawable();
contentDrawable.setColor(Color.WHITE);
contentDrawable.setCornerRadius(16);
RippleDrawable rippleDrawable = new RippleDrawable(pressedStates, contentDrawable, null);
container.setBackground(rippleDrawable);https://stackoverflow.com/questions/44245757
复制相似问题