Android以编程方式将Radius设置为ShapeDrawable [英] Android set radius programatically to ShapeDrawable

查看:179
本文介绍了Android以编程方式将Radius设置为ShapeDrawable的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

Can I set a radius programmatically to a ShapeDrawable?

推荐答案

您可以这样做:

You can do it like this:

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);
}

您可以在整个应用程序中使用此功能,并可以选择所需的边框和背景颜色.

You can use this function throughout your app and can put border and background color of your choice.

这篇关于Android以编程方式将Radius设置为ShapeDrawable的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆