【问题标题】:Android set radius programatically to ShapeDrawableAndroid以编程方式将半径设置为ShapeDrawable
【发布时间】:2017-08-19 17:58:36
【问题描述】:

我可以通过编程将半径设置为 ShapeDrawable 吗?

【问题讨论】:

标签: android android-shapedrawable


【解决方案1】:

试试这个:

        LayerDrawable bgDrawable = (LayerDrawable) btnCallnow.getBackground();
        final GradientDrawable shape = (GradientDrawable) bgDrawable.findDrawableByLayerId(R.id.shape_id);
        shape.setCornerRadius(5.0f);

【讨论】:

  • 我没有看到 ShapeDrawable 的任何用途?
  • Shape_id 是自定义可绘制形状的 id。
【解决方案2】:

你可以这样做:

public static void customView(View v, int backgroundColor, int   borderColor)
{
  GradientDrawable shape = new GradientDrawable();
  shape.setShape(GradientDrawable.RECTANGLE);
  shape.setCornerRadii(new float[] { 8, 8, 8, 8, 0, 0, 0, 0 });
  shape.setColor(backgroundColor);
  shape.setStroke(3, borderColor);
  v.setBackgroundDrawable(shape);
}

您可以在整个应用程序中使用此功能,并且可以放置您选择的边框和背景颜色。

【讨论】:

  • 我没有看到 ShapeDrawable 的任何用途?
猜你喜欢
  • 2016-01-07
  • 1970-01-01
  • 2015-09-15
  • 2013-01-19
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2015-10-12
相关资源
最近更新 更多