Android - 如何使图标在触摸时发光? [英] Android - How to make an icon glow on touch?

查看:282
本文介绍了Android - 如何使图标在触摸时发光?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如何在图标上获得此蓝色发光效果?这有什么快速的方法吗?我真的不想使用photoshop来达到这种效果。

How to get this blue glow effect over an icon? Is there any quick way of doing it? I really don't want to use photoshop for this effect.

我们非常感谢任何帮助。

Any help would be really appreciated.

推荐答案

如果你想以编程方式生成光晕,请按照以下方法可以做。我的建议是,在你的活动开始时只生成一次,然后使用它创建一个StateListDrawable,如评论中所述:

If you want to generate the glow programatically, here's how you can do. My advice, generate it just once at the beggining of your activity, then create a StateListDrawable using it, as said in the comment :

    // An added margin to the initial image
    int margin = 24;
    int halfMargin = margin / 2;

    // the glow radius
    int glowRadius = 16;

    // the glow color
    int glowColor = Color.rgb(0, 192, 255);

    // The original image to use
    Bitmap src = BitmapFactory.decodeResource(getResources(),
            R.drawable.ic_launcher);

    // extract the alpha from the source image
    Bitmap alpha = src.extractAlpha();

    // The output bitmap (with the icon + glow)
    Bitmap bmp = Bitmap.createBitmap(src.getWidth() + margin,
            src.getHeight() + margin, Bitmap.Config.ARGB_8888);

    // The canvas to paint on the image
    Canvas canvas = new Canvas(bmp);

    Paint paint = new Paint();
    paint.setColor(glowColor);

    // outer glow
    paint.setMaskFilter(new BlurMaskFilter(glowRadius, Blur.OUTER));
    canvas.drawBitmap(alpha, halfMargin, halfMargin, paint);

    // original icon
    canvas.drawBitmap(src, halfMargin, halfMargin, null);

    ((ImageView) findViewById(R.id.bmpImg)).setImageBitmap(bmp);

这篇关于Android - 如何使图标在触摸时发光?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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