Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Android ShapeDrawable set Background and Border programmatically

I have a ShapeDrawable:

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

I want to set border(stroke) color and width for this drawable.

I try setStyle(Paint.Style.FILL_AND_STROKE) but it set background and border with same color

like image 241
Hossain Khademian Avatar asked Jun 28 '15 19:06

Hossain Khademian


1 Answers

Use

drawable.getPaint().setStyle(Paint.Style.STROKE);
drawable.getPaint().setStrokeWidth(2); // in pixel
like image 167
Richard Chang Avatar answered Oct 28 '22 04:10

Richard Chang