我想在现有的drawable上绘制一个数字。就像电子邮件图标上的未读数。 drawable是按钮的顶部图标。这是我的代码:Drawable Drawable
BitmapDrawable d = (BitmapDrawable) button.getCompoundDrawables()[1];
if(d != null) {
Bitmap src = d.getBitmap();
Bitmap b = Bitmap.createBitmap(src.getWidth(), src.getHeight(), src.getConfig());
Canvas c = new Canvas(b);
Paint p = new Paint();
p.setAntiAlias(true);
p.setStrokeWidth(1);
p.setStyle(Style.FILL_AND_STROKE);
p.setColor(Color.rgb(254, 0, 1));
c.drawBitmap(src, 0, 0, p);
c.drawCircle(b.getWidth()-5, 5, 5, p);
button.setCompoundDrawables(null, new BitmapDrawable(b), null, null);
}
生成的drawable是emtpy。这段代码有什么问题吗?
在此先感谢。