Android ShapeDrawable以编程方式设置背景和边框 [英] Android ShapeDrawable set Background and Border programmatically

查看:833
本文介绍了Android ShapeDrawable以编程方式设置背景和边框的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个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.

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

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

推荐答案

使用

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

这篇关于Android ShapeDrawable以编程方式设置背景和边框的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆