Android ShapeDrawable以编程方式设置Background和Border

时间:2015-06-28 19:38:28

标签: android drawable paint android-drawable

我有ShapeDrawable

final ShapeDrawable drawable = new ShapeDrawable(shape);
drawable.getPaint().setStyle(Paint.Style.FILL);
drawable.getPaint().setColor(0xFFffffff);

我想为这个drawable设置边框(笔触)颜色和宽度。

我尝试setStyle(Paint.Style.FILL_AND_STROKE) 但它用相同的颜色设置背景和边框

1 个答案:

答案 0 :(得分:3)

使用

drawable.getPaint().setStyle(Paint.Style.STROKE);
drawable.getPaint().setStrokeWidth(2); // in pixel