Question

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.

Was it helpful?

Solution 2

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

OTHER TIPS

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.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top