0

My problem is simple: how to make same android homescreen icon effect on clicking them? In other words how to make that temporary back lighting effect? In general how to implement android image buttons backlight effect that surround picture edge? Possibly I want to make it programmatically without insert a lot of images in my app. Thanks in advance.

Domenico Pacecca
  • 295
  • 1
  • 7
  • 14

2 Answers2

0

Suppose this is my test_button.xml

<?xml version="1.0" encoding="utf-8"?>
<selector xmlns:android="http://schemas.android.com/apk/res/android">
<item android:state_pressed="true"  android:drawable="@drawable/test_effect" />
<item android:state_pressed="false"  android:drawable="@drawable/your_image_name" />
<item android:drawable="@drawable/your_image_name" />   <!-- default  -->

This is how your test_effect.xml should look:

<?xml version="1.0" encoding="utf-8"?>

<item>
    <shape android:shape="rectangle">
        <gradient
            android:endColor="#3399CCFF"
            android:startColor="#8899CCFF"/>


        <padding android:top="5dp" android:right="5dp" android:bottom="5dp" android:left="5dp" />
        <corners android:radius="5dp"/>
    </shape>
</item>

<!-- Background -->
<item android:drawable="@drawable/your_image_name"/>

Note: your_image_name is the same everywhere.

LoveMeSomeFood
  • 3,137
  • 7
  • 30
  • 53
  • thanks for writing code, my doubt is: this way you describe gradient covering all the background and I am already able to do that, but I want to design a second fading line that follows perfectly the edge of picture inside the View: image a body with transparent background and I want fading line to be parallel to body edge. I dont Know if I'm able to explain it... – Domenico Pacecca Nov 08 '13 at 21:08
  • I'm sorry but I couldn't get what you say. =/ – LoveMeSomeFood Nov 08 '13 at 21:19
  • I have just found something about my problem: constant EFFECT_FILLLIGHT but I dont understand how to use it, can you take a look at that please? http://developer.android.com/reference/android/media/effect/EffectFactory.html#isEffectSupported(java.lang.String) – Domenico Pacecca Nov 08 '13 at 21:33
  • I mean an "aura" effect, possibly without design a new background for every image. – Domenico Pacecca Nov 09 '13 at 11:03
0

I found something working:

   public Bitmap highlightImage(Bitmap src) {
        // create new bitmap, which will be painted and becomes result image
        Bitmap bmOut = Bitmap.createBitmap(src.getWidth() , src.getHeight() ,   Bitmap.Config.ARGB_8888);
        // setup canvas for painting
        Canvas canvas = new Canvas(bmOut);
        // setup default color
        canvas.drawColor(0, PorterDuff.Mode.CLEAR);
        // create a blur paint for capturing alpha
        Paint ptBlur = new Paint();
        ptBlur.setMaskFilter(new BlurMaskFilter(15, Blur.NORMAL));
        int[] offsetXY = new int[2];
        // capture alpha into a bitmap
        Bitmap bmAlpha = src.extractAlpha(ptBlur, offsetXY);
        // create a color paint
        Paint ptAlphaColor = new Paint();
        ptAlphaColor.setColor(0xFFFFFFFF);
        // paint color for captured alpha region (bitmap)
        canvas.drawBitmap(bmAlpha, offsetXY[0], offsetXY[1], ptAlphaColor);
        // free memory
        bmAlpha.recycle();

        // paint the image source
        canvas.drawBitmap(src, 0, 0, null);

        // return out final image
        return bmOut;
    }

You can use this method for example in an onclick button to highlight edge of a bitmap

Domenico Pacecca
  • 295
  • 1
  • 7
  • 14