Android ShapeDrawable set Background and Border programmatically

一笑奈何 提交于 2020-01-03 16:57:05

问题


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


回答1:


Use

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


来源:https://stackoverflow.com/questions/31103974/android-shapedrawable-set-background-and-border-programmatically

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!