Sunday, December 28, 2014

It is possible to create this simple shape as tag picture in Android code behind

Shape shape = new Shape() {
    Path path = new Path();
    @Override
    protected void onResize(float width, float height) {
        path.reset();
        path.lineTo(width - height / 2, 0);
        path.lineTo(width, height / 2);
        path.lineTo(width - height / 2, height);
        path.lineTo(0, height);
        path.close();
    }
    @Override
    public void draw(Canvas canvas, Paint paint) {
        canvas.drawPath(path, paint);
    }
};
ShapeDrawable d = new ShapeDrawable(shape);
d.getPaint().setColor(0xff6699bb);

someView.setBackgroundDrawable(d);
result:

No comments: