我的问题很简单:如何在点击它们时制作相同的android主屏幕图标效果?换句话说,如何制作临时背光效果?一般如何实现android图像按钮背光效果,环绕画面边缘?可能我想以编程方式进行编程而不在我的应用程序中插入大量图像。提前谢谢。
答案 0 :(得分: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在任何地方都是一样的。
答案 1 :(得分: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按钮中使用此方法突出显示位图的边缘