I know this topic has been discussed yet but I didn't find really what I wanna do.
I have those buttons (screenshot at the bottom). Now I want to add a outer glow. Is there an other possibility to do this than saving it as .png in the drawable folder? That would make much less work.
Greetings
Nils
解决方案
try this code
public Bitmap setGlow(int resourceId) {
Bitmap bmp = null;
try {
int margin = 30;
int halfMargin = margin / 2;
int glowRadius = 15;
int glowColor = Color.rgb(0, 192, 200);
Bitmap src = BitmapFactory.decodeResource(getResources(),
resourceId);
Bitmap alpha = src.extractAlpha();
bmp = Bitmap.createBitmap(src.getWidth() + margin, src.getHeight()
+ margin, Bitmap.Config.ARGB_8888);
Canvas canvas = new Canvas(bmp);
Paint paint = new Paint();
paint.setColor(glowColor);
paint.setMaskFilter(new BlurMaskFilter(glowRadius, Blur.OUTER));
canvas.drawBitmap(alpha, halfMargin, halfMargin, paint);
canvas.drawBitmap(src, halfMargin, halfMargin, null);
} catch (Exception e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
return bmp;
}
and set the returned bitmap on your view
set in your imagebutton like this
btnClick.setImageBitmap(setGlow(R.drawable.ic_launcher));