0

我的问题很简单:如何在单击它们时使相同的 android 主屏幕图标效果?换句话说,如何制作那种临时的背光效果?一般如何实现环绕图片边缘的android图像按钮背光效果?可能我想以编程方式制作它而不在我的应用程序中插入大量图像。提前致谢。

4

2 回答 2

0

假设这是我的 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  -->

这就是您的 test_effect.xml 的外观:

<?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"/>

注意:your_image_name 到处都是一样的。

于 2013-11-08T19:11:03.303 回答
0

我发现了一些工作:

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

例如,您可以在 onclick 按钮中使用此方法来突出显示位图的边缘

于 2014-02-08T23:42:24.830 回答