Android - ¿Cómo hacer que un ícono brille al tocarlo?

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.

Cualquier ayuda sería realmente apreciada.

preguntado el 28 de agosto de 12 a las 11:08

You have to make use of statelistdrawables in which you will define the blue effect.Please visit the thread stackoverflow.com/questions/6501716/… O puedes visitar desarrollador.android.com/guide/topics/resources/… -

1 Respuestas

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);

Respondido 28 ago 12, 15:08

I really like the way you explained the stuff using comments. Thanks. - Varundroid

No es la respuesta que estás buscando? Examinar otras preguntas etiquetadas or haz tu propia pregunta.