是否可以通过编程方式禁用描边样式的绘画底部

时间:2017-05-05 07:36:47

标签: java android border paint

我使用自定义类扩展了ShapeDrawable,以编程方式绘制背景和自定义颜色边框。

代码:

public class CustomBorderDrawable extends ShapeDrawable {
private Paint fillpaint, strokepaint;
private int WIDTH = 3;

public CustomBorderDrawable(Shape s) {
    super(s);
    fillpaint = this.getPaint();
    strokepaint = new Paint(fillpaint);
    strokepaint.setStyle(Paint.Style.STROKE);
    strokepaint.setStrokeWidth(WIDTH);
    strokepaint.setARGB(255, 0, 0, 0);
}

@Override
protected void onDraw(Shape shape, Canvas canvas, Paint fillpaint) {
    shape.draw(canvas, fillpaint);
    shape.draw(canvas, strokepaint);
}

public void setFillColour(int c){
    fillpaint.setColor(c);
}

public void setBorderColour(int c){
    strokepaint.setColor(c);
}

public void setStrokeWidth(int px){
    this.WIDTH = px;
    strokepaint.setStrokeWidth(WIDTH);
}

public void setBottomEnable(boolean enable){
    //TODO
}}

如您所见,我想添加一个允许启用或不启用笔画底部的功能。

我只找到了XML解决方案,如何以编程方式完成?

解决方法可能是在我的边框底部放置一个条形图,但我不知道该怎么做。

1 个答案:

答案 0 :(得分:0)

如果您只想禁用笔画,请调用 setStrokeWidth(0)。将宽度设置为0将不会显示笔划。