【发布时间】:2018-11-15 11:11:41
【问题描述】:
有一些类似的问题。但他们没有解决!
Set RippleDrawable corner radius programmatically
我知道这种行为可以做到using xml file。但我必须以编程方式进行。
我的代码如下:
GradientDrawable gd = new GradientDrawable();
gd.setColor(Color.YELLOW);
gd.setStroke(2, Color.RED);
gd.setCornerRadius(45.0f);
view.setBackground(gd);
int[] colors = new int[]{Color.GRAY};
int[][] states = new int[][]{ new int[]{}};
ColorStateList stateList = new ColorStateList(states, colors);
Drawable mask = getResources().getDrawable(R.drawable.icon1);
RippleDrawable rippleDrawableBackgorund = new RippleDrawable(stateList, view.getBackground(), mask);
view.setBackground(rippleDrawableBackgorund);
按下状态的截图如下:
如何为 RippleDrawable 设置边框半径?此外,rippleDrawableBackgorund.setRadius 将这种效果更改为悬停状态。
【问题讨论】:
-
不重复。我想以编程方式创建而不是 xml。
-
但是您可以通过与 XML 中类似的命名方法以相同的方式设置可绘制对象。
标签: android-layout ripple android-background rippledrawable