Android:以编程方式为imageButton添加半径

时间:2014-12-06 12:20:20

标签: android

如何以编程方式为imageButton对象添加半径?
我检查了这个网站上存在的主题,但我找不到我的答案? 我想添加没有xml文件的半径

2 个答案:

答案 0 :(得分:0)

我认为你应该使用GradientDrawable

这是一个例子:

GradientDrawable gdDefault = new GradientDrawable();
ColorDrawable cd = new ColorDrawable(0xFFFF6666);
gdDefault.setColor(bgColor);
gdDefault.setCornerRadius(cornerRadius);
gdDefault.setStroke(strokeWidth, strokeColor);
yourView.setBackgroundDrawable(cd);

答案 1 :(得分:0)

您可以使用GradientDrawable。

 GradientDrawable shape =  new GradientDrawable();
 shape.setCornerRadius(8);

 ImageButton ivButton = (ImageButton) findViewById( R.id.ivbtn );
 ivButton.setBackgroundDrawable(shape);

享受!!!